cnblogs/dcrenl/jquery获取浏览器类型和版本号的方法.html

23 lines
1.4 KiB
HTML
Raw Permalink Normal View History

2024-09-24 12:43:01 +08:00
<p>$(document).ready(function(){</p>
<p>varbrow=$.browser;</p>
<p>varbInfo="";</p>
<p>if(brow.msie){bInfo="MicrosoftInternetExplorer"+brow.version;}</p>
<p>if(brow.mozilla){bInfo="MozillaFirefox"+brow.version;}</p>
<p>if(brow.safari){bInfo="AppleSafari"+brow.version;}</p>
<p>if(brow.opera){bInfo="Opera"+brow.version;}</p>
<p>alert(bInfo);</p>
<p>});</p>
<p>&nbsp;</p>
<p>jQuery&nbsp;&nbsp;从 1.9 版开始,移除了 $.browser 和 $.browser.version 取而代之的是 $.support 方法,如果需要了解 $.support 请参考:</p>
<p>jQuery 1.9使用$.support替代$.browser方法</p>
<p>&nbsp;</p>
<p>或使用js 方法:</p>
<p>&nbsp;</p>
<p><span style="color: #666666;">var browser = navigator.appName;</span></p>
<p><span style="color: #666666;">&nbsp;&nbsp;&nbsp;&nbsp;var b_version = navigator.appVersion;</span></p>
<p><span style="color: #666666;">&nbsp;&nbsp;&nbsp;&nbsp;var version = b_version.split(";");</span></p>
<p><span style="color: #666666;">&nbsp;&nbsp;&nbsp;&nbsp;var trim_Version = version[1].replace(/[ ]/g, "");</span></p>
<p><span style="color: #666666;">&nbsp;</span></p>
<p><span style="color: #666666;">&nbsp;&nbsp;&nbsp;&nbsp;if (browser == "Microsoft Internet Explorer" &amp;&amp; trim_Version == "MSIE9.0") {</span></p>
<p><span style="color: #666666;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert("IE9");</span></p>
<p><span style="color: #666666;">&nbsp;&nbsp;&nbsp;&nbsp;}</span></p>