[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[转帖]烦人的IE9----------- IE9 : DOM Exception: INVALID_CHARACTER_ERR (5)

上一篇:[备忘]IE9,fckeditor的对话框,出现“调用的对象无效”的JS错误~~
下一篇:[转帖]IE9的Js错误:jquery.bgiframe.min.js, 行10 字符978

添加日期:2013/4/25 17:29:36 快速返回   返回列表 阅读3974次
IE太烦人了,版本之间还不兼容。

[url]http://blog.csdn.net/a497785609/article/details/6317502[/ur]

以下代码在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";

 

评论 COMMENTS
没有评论 No Comments.

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved