閱讀964 返回首頁    go 阿裏雲 go 技術社區[雲棲]


IE9 : DOM Exception: INVALID_CHARACTER_ERR (5)

以下代碼在IE8下運行通過,在IE9中出錯:
document.createElement('<iframe src="../../images/defaults/transparent-pixel.gif" ></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";

 

最後更新:2017-04-02 06:51:39

  上一篇:go 關於Myeclipse8.6和 Flex4 插件安裝,進度不走的問題解決辦法
  下一篇:go Git服務器Gitosis安裝設置