以下代码在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";
相关推荐
主要介绍了IE9+已经不对document.createElement向下兼容的解决方法,需要的朋友可以参考下
今天处理了一个日期选择器的ie和ff的兼容问题,本来这种情况就很难找错误,找了好久才把错误定位到js中创建元素的方法document.createElement(),这个方法在ie下支持这样创建元素
复制代码代码如下: document.createElement(‘header’); document.createElement(‘nav’); document.createElement(‘section’); document.createElement(‘article’); document.createElement(‘aside’); ...
以上代码在ie8兼容模式和ff6下都没有总是,但在ie8不兼容模式下不起作用,只有在appendChild后,再设置checked的值就都起作用,如下: 代码如下: var chk = document.createElement(“input”)
代码如下: AddCss=function(c){ var Sty=document.createElement(‘style’); Sty.type=’text/css’; if(Browser.ie){ Sty.styleSheet.cssText=c; }else{ var Frag=document.createDocumentFragment(); Frag....
html 5 有个很棒的属性,placeholder,在鼠标聚焦到上面时候,提示文字会消失,失去焦点之后,又会出现: ...(‘placeholder’ in document.createElement(‘input’))) { var self = placeholder; el.each(functio
开始代码是这么写的: 代码如下:var a = document.createElement(“a”);a.setAttribute(“onclick”, this.ClickFunctionName + “(” + pageIndex + “);Pager.SetCurrent(” + pageIndex + “);”);由于IE8不支持...
让IE(包括IE6)支持HTML5元素,我们需要在HTML头部添加以下JavaScript,这是一个简单的document.createElement声明,利用条件注释针对IE来调用这个js文件。Opera,FireFox等其他非IE浏览器就会忽视这段代码,也不会...
本文实例讲述了IE8中动态创建script标签onload无效的解决方法。... script = document.createElement(“script”); script.type = “text/javascript”; script.src = src; if(typeof fun
以下代码在IE8下运行通过,在IE9中出错: 代码如下:document.createElement(‘<iframe id=”yige-org-iframe” src=”yige.org.logo.gif” style=”position:absolute;top:0;left:0;width:1px;height:1px;...
ie-css-transform ...var el = document . createElement ( 'div' ) ; applyTransform ( el , 'perspective(1000px) translate3d(100px, 100px, 500px)' , '0% 0%' ) ; el . style . width = el . styl
今天一个项目中需要判断IE版本号,又因为 jQuery 2.0 去除了对浏览器版本号的判断(它推荐特性检测),于是就看到一老外写的一段代码: 代码如下: var _IE = (function(){ var v = 3, div = document.createElement...
代码如下: var iframe = document.createElement(“iframe”); iframe.id = “frame-” + index; iframe.src = url; iframe.width = “100%”; iframe.marginwidth = “0”; iframe.scrolling = “no”; iframe....
方法一: 用的浏览器内部转换器实现转换,方法是动态创建一个容器标签元素,如DIV,将要转换的字符... 代码如下:[removed] function HTMLEncode(html) { var temp = document.createElement (“div”); (temp.textConte
Js导出表格为Excel文件 的常见一种办法是调用:ActiveXObject(“Excel.Application”) ,但是这种方法有局限性,只能在IE系列下的浏览器...var downloadLink = document.createElement(“a”);downloadLink.href = uri;
对于非ie浏览器他是用flash来实现的,js代码如下: 代码如下: [removed] function copy_code(copyText) { if (window....document.getElementById(flashcopier)) { var divholder = document.createElement(
HTML5规范毕竟是刚刚才定义完成的规范,还有一些浏览器并不能支持...庆幸的是IE8/IE7/IE6支持通过document.createElement方法产生的标签,可以利用这一特性让这些浏览器支持HTML5新标签,代码如下: var e = abbr, ar