The following code runs successfully under IE8 but fails in IE9:
document.createElement('');
Error message: exception: SCRIPT5022: DOM Exception: INVALID_CHARACTER_ERR (5)
Idea analysis:
Step one: Compatible with IE9, firefox, Opera, Safari and other browsers;
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;");
Step 2: Compatible with IE6-8: Because ie6-8 cannot modify the name attribute of the iframe
var oFrame = isIE ? document.createElement("
Comprehensive solution:
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("