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";
?
轉載于:https://www.cnblogs.com/zhangqs008/archive/2011/04/12/2341141.html
總結
以上是生活随笔為你收集整理的IE9 : DOM Exception: INVALID_CHARACTER_ERR (5)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 求一个分手的微信网名
- 下一篇: 使用 雨林木风 Ghost XP SP3