打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
IE9 : DOM Exception: INVALID_CHARACTER_ERR (5)

IE9 : DOM Exception: INVALID_CHARACTER_ERR (5)

IE9创建DOM元素的方式较之前有了改变,开始严格遵循标准的实现,不允许通过直接传入一个完整html标记的方式来创建Dom元素。

document.createElement('<iframe id="yui-history-iframe" src="//images.cnblogs.com/defaults/transparent-pixel.gif" style="position:absolute;top:0;left:0;width:1px;height:1px;visibility:hidden;"></iframe>');


解决方法:

采用标准的方式来实现:

if( $.browser.msie &&/9.0/.test(navigator.userAgent)){
                var iframe = document.createElement("iframe");
                iframe.setAttribute("class","bgiframe");
                iframe.setAttribute("frameborder","0");
                iframe.setAttribute("style","display:block;position:absolute;z-index:-1;filter:Alpha(Opacity=\'0\');top:(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\');left:(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\');width:(this.parentNode.offsetWidth+\'px\');height:(this.parentNode.offsetHeight+\'px\');");
                this.insertBefore( iframe,this.firstChild );
            }else{
                this.insertBefore( document.createElement(html),this.firstChild );
            }

 

 

________________zhuanzai_____________________________________________________________ 

 

 

以下代码在IE8下运行通过,在IE9中出错:
document.createElement('<iframe id="yui-history-iframe" src="//images.cnblogs.com/defaults/transparent-pixel.gif" style="position:absolute;top:0;left:0;width:1px;height:1px;visibility:hidden;"></iframe>');
错误提示:exception : SCRIPT5022: DOM Exception: INVALID_CHARACTER_ERR (5)


思路分析:
第一步:兼容IE9,firefox,Opera,Safari等浏览器;
var iframe = document.createElement("iframe");
iframe.setAttribute("id", "yui-history-iframe");
iframe.setAttribute("src", "http://images.cnblogs.com/defaults/transparent-pixel.gif");
iframe.setAttribute("style","position:absolute;top:0;left:0;width:1px;height:1px;visibility:hidden;");

第二步:兼容IE6-8:由于ie6-8 不能修改iframe的name属性
var oFrame = isIE ? document.createElement("<iframe name=/"" + this._FrameName + "/">") : document.createElement("iframe");
oFrame.name = "iframName";


综合解决办法:

        var isIE = (document.all) ? true : false;//这里仅仅简单的对是否是IE进行判断,详细浏览器判断:请参考浏览器类型侦测
        var ua = navigator.userAgent.toLowerCase().match(/msie ([/d.]+)/)[1];
        if (ua == "9.0") {
            isIE = false;
        }
var oFrame = isIE ? document.createElement("<iframe name=/"" + this._FrameName + "/">") : document.createElement("iframe");
oFrame.name = "iframName";


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
IE7下动态创建Iframe时,去除边框的办法
检测浏览器对事件不同的处理方式
W3C DOM异常对象DOMException介绍 ? 张鑫旭
IE7下动态创建Iframe时,去除边框
2014年最新前端开发面试题(面霸题库)
Firefox 不支持 DOM 对象的 insertAdjacentHTML insertAdjacentText 方法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服