test.js
var win = window; var doc = win.document; var input = doc.createElement ("input"); var ie = (function (){ //"!win.ActiveXObject" is evaluated to true in IE11 if (win.ActiveXObject === undefined) return null; if (!win.XMLHttpRequest) return 6; if (!doc.querySelector) return 7; if (!doc.addEventListener) return 8; if (!win.atob) return 9; //"!doc.body.dataset" is faster but the body is null when the DOM is not //ready. Anyway, an input tag needs to be created to check if IE is being //emulated if (!input.dataset) return 10; return 11; })(); if(ie<9){ var dd=document.createElement("div"); dd.innerHTML=\'<div style="position:absolute;top:0;height:30px; line-height:30px;;width:100%;color:#272726; text-align:center; background:#fbee25;font-size:16px;"></div>\'; document.body.appendChild(dd); var text=document.createTextNode("您正在使用 Internet Explorer "+ie+" 低版本浏览器。为更好的浏览本页,建议您将浏览器升级到IE9以上或其它主流浏览器,以免影响您的正常使用!"); dd.childNodes[0].appendChild(text); }