zoukankan      html  css  js  c++  java
  • IE9 : DOM Exception: INVALID_CHARACTER_ERR (5)

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

    document.createElement('<iframe id="yui-history-iframe" src="http://images.cnblogs.com/defaults/transparent-pixel.gif" style="position:absolute;top:0;left:0;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:expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\');left:expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\');expression(this.parentNode.offsetWidth+\'px\');height:expression(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="http://images.cnblogs.com/defaults/transparent-pixel.gif" style="position:absolute;top:0;left:0;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;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";

  • 相关阅读:
    SpringCloud教程 | 第六篇: 分布式配置中心(Spring Cloud Config)(Finchley版本)
    SpringCloud教程 | 第五篇: 路由网关(zuul)(Finchley版本)
    SpringCloud教程 | 第四篇:断路器(Hystrix)(Finchley版本)
    SpringCloud教程 | 第三篇: 服务消费者(Feign)(Finchley版本)
    SpringCloud教程 | 第二篇: 服务消费者(rest+ribbon)(Finchley版本)
    SpringCloud 教程 | 第一篇: 服务的注册与发现Eureka(Finchley版本)
    linux查看日志文件内容命令tail、cat、tac、head、echo详解
    codevs 1462 素数和
    Codevs 1313 质因数分解
    Open Judge 1.4 09
  • 原文地址:https://www.cnblogs.com/yuzhongwusan/p/2588226.html
Copyright © 2011-2022 走看看