>使用JavaScript和jQuery检测Internet Explorer版本:综合指南
本指南使用JavaScript和jQuery编译了用于确定Internet Explorer版本的各种方法。 如果您知道其他技术,请分享它们!
方法1:基本IE7 Check(JavaScript)
>> Internet Explorer的简单检查7:
<code class="language-javascript">//check for IE7 if(navigator.appVersion.indexOf("MSIE 7.")!=-1) { // IE7 specific code here }</code>
方法2:使用Modernizr(JavaScript)
> Modernizr提供了一种可检测浏览器功能的强大方法,包括IE版本。
<code class="language-javascript">//check for IE8 or less if ($('html').hasClass('lt-ie8')) { // IE8 or lower specific code here } //example of HTML tag populated by modernizer</code>
方法3:jQuery的$ ..兄弟(已弃用)
>注意:自JQuery 1.9以来已被弃用。此方法将在较新的jQuery版本中起作用。$.browser
>
<code class="language-javascript">//check for IE8 or less (DEPRECATED) if($.browser.msie && parseFloat($.browser.version)<8){ //do other stuff return; }</code>
>方法4:CSS有条件注入(JavaScript)>
这种聪明的技术避免了用户代理的嗅探:
<code class="language-javascript">var ie = (function(){ var undef, v = 3, div = document.createElement('div'), all = div.getElementsByTagName('i'); while (div.innerHTML = '', all[0]); return v > 4 ? v : undef; }());</code>
方法5:IE10 Check(JavaScript)>
>用于检测IE10的用户代理嗅探方法:>
<code class="language-javascript">(function() { "use strict"; var tmp = (document["documentMode"] || document.attachEvent) && "ev", msie = tmp && (tmp = window[tmp + "al"]) && tmp("/*@cc_on 1;@*/") && +((/msie (d+)/i.exec(navigator.userAgent) || [])[1] || 0); return msie || void 0; })();</code>
方法6:基本HTML条件
这是一种常见的方法,通常直接在HTML中看到:
<code class="language-html"><!-- Example: Conditional CSS inclusion --> <!--[if IE 8]> <link rel="stylesheet" href="ie8.css"> <![endif]--></code>常见问题(FAQS)
> >
如何在Windows 10上检查IE版本:> 打开Internet Explorer。
> Internet Explorer更新:
Internet Explorer vs. Microsoft Edge:
Internet Explorer不适用于Mac或移动设备。
>检查JavaScript/jQuery版本:
>使用在线工具(例如JSFiddle或JavaScript测试仪)检查您的JavaScript版本。 对于jQuery,在浏览器的控制台中使用。>
故障排除网站在IE中显示问题:
尝试使用Internet Explorer的兼容性视图。 记住要分享任何进一步的方法或见解以帮助改善支持!
以上是使用JavaScript/jQuery检查IE版本的5种方法的详细内容。更多信息请关注PHP中文网其他相关文章!