IE9 : DOM Exception: INVALID_CHARACTER_ERR (5)

简介:

以下代码在IE8下运行通过,在IE9中出错:
document.createElement('<iframe id="yui-history-iframe" src="../../images/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", "../../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("<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";

 

目录
相关文章
|
4月前
Flutter-解决Try catch出现异常:type ‘_TypeError‘ is not a subtype of type ‘Exception‘ in type cast
Flutter-解决Try catch出现异常:type ‘_TypeError‘ is not a subtype of type ‘Exception‘ in type cast
81 1
|
PHP
Fatal error: Can't use method return value in write context in
说明:   php环境测试会报错下面错误:Fatal error: Can't use method return value in write context in    解决方案:   首先检查自己的php版本,支付宝sdk和demo测试需要php5.5以上版本。
956 12
|
5月前
|
JSON Java 数据格式
JSON parse error: Unexpected character (‘t‘ (code 116)): was expecting double-quote to start field n
JSON parse error: Unexpected character (‘t‘ (code 116)): was expecting double-quote to start field n
|
7月前
|
API Android开发 开发者
failed to set system property error code: 0x18
failed to set system property error code: 0x18
301 1
|
7月前
|
JSON 数据格式
“JSON parse error: Unexpected character (‘1‘ (code 49))的解决方式
“JSON parse error: Unexpected character (‘1‘ (code 49))的解决方式
|
7月前
|
Perl
报错:error Parsing error: x-invalid-end-tag
报错:error Parsing error: x-invalid-end-tag
140 0
Uniapp Syntax Error: Error: Unbalanced delimiter found in string
Uniapp Syntax Error: Error: Unbalanced delimiter found in string
258 0
Java.sql.SQLException: Illegal operation on empty result set.
Java.sql.SQLException: Illegal operation on empty result set.
279 0
|
SQL 关系型数据库 数据库
[Err] ERROR: invalid input syntax for integer: "1.0"
[Err] ERROR: invalid input syntax for integer: "1.0"
1076 0
[Err] ERROR: invalid input syntax for integer: "1.0"