以下代码在IE8下运行通过,在IE9中出错:
document.createElement('');
错误提示: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", "../../images/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(" 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(" name=/"" + this._FrameName + "/">") : document.createElement("iframe");
oFrame.name = "iframName";
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/a497785609/archive/2011/04/12/6317502.aspx
IE9 : DOM Exception: INVALID_CHARACTER_ERR (5)
最新推荐文章于 2023-05-16 11:46:23 发布
本文提供了一种解决IE9下创建iframe元素时出现DOM异常的方法。通过对不同版本IE的判断,实现了兼容IE6-8及IE9以上版本的代码方案。

7054

被折叠的 条评论
为什么被折叠?



