我這是進行判斷瀏覽器
css判斷ie版本才引用樣式或css文件
<!--[if !IE]><!--> 除IE外都可識別 <!--<![endif]--> <!--[if IE]> 所有的IE可識別 <![endif]--> <!--[if IE 6]> 僅IE6可識別 <![endif]--> <!--[if lt IE 6]> IE6以下版本可識別 <![endif]-->
或者這樣,直接解決:
<!--判斷IE瀏覽器版本--> <script> window.AESKey = ''; // 判斷瀏覽器是否支持placeholder屬性 function isSupportPlaceholder() { var input = document.createElement('input'); return 'placeholder' in input; }; (function() { //判斷是否是IE瀏覽器,包括Edge瀏覽器 function IEVersion() { //取得瀏覽器的userAgent字符串 var userAgent = navigator.userAgent; //判斷是否IE瀏覽器 var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; if (isIE) { var reIE = new RegExp("MSIE (\\d+\\.\\d+);"); reIE.test(userAgent); var fIEVersion = parseFloat(RegExp["$1"]); if (fIEVersion < 10 || !isSupportPlaceholder()) { return true; } } else { return false; } } var tpl = [ '<div class="browser-tips" style="margin:0 auto;text-align: center;">', '<img style="display: inline-block;margin:100px 0 20px 0;" src="error.png">', '<p style="font-size: 20px;color:#000;line-height: 32px;">為了給您提供更優質的網頁瀏覽體驗,建議使用IE10及以上版本的瀏覽器</p>', '<p style="font-size: 20px;color:#000;line-height: 32px;">對“本網站”進行訪問,請升級或更換其他瀏覽器</p>', '</div>' ].join(''); window.onload = function() { if (IEVersion()) { document.write(tpl); } }; window.siteName = "本網站好啊好啊"; })(); </script>