Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何识别浏览器?_Javascript_Html_Browser - Fatal编程技术网

Javascript 如何识别浏览器?

Javascript 如何识别浏览器?,javascript,html,browser,Javascript,Html,Browser,可能重复: 在HTML/JavaScript中,如何识别用户正在使用的浏览器,并选择代码,我的意思是:如果浏览器是crhome,那么就这样做。。。其他的 谢谢您可以使用navigator完成此操作并获取所有详细信息。只要做一个谷歌搜索 <div id="example"></div> <script type="text/javascript"> txt = "<p>Browser CodeName: " + navigator.appCod

可能重复:

在HTML/JavaScript中,如何识别用户正在使用的浏览器,并选择代码,我的意思是:如果浏览器是crhome,那么就这样做。。。其他的 谢谢

您可以使用navigator完成此操作并获取所有详细信息。只要做一个谷歌搜索

<div id="example"></div>

<script type="text/javascript">

txt = "<p>Browser CodeName: " + navigator.appCodeName + "</p>";
txt+= "<p>Browser Name: " + navigator.appName + "</p>";
txt+= "<p>Browser Version: " + navigator.appVersion + "</p>";
txt+= "<p>Cookies Enabled: " + navigator.cookieEnabled + "</p>";
txt+= "<p>Platform: " + navigator.platform + "</p>";
txt+= "<p>User-agent header: " + navigator.userAgent + "</p>";

document.getElementById("example").innerHTML=txt;

</script>

希望这有帮助!:

不建议检测浏览器,因为浏览器是移动目标。例如,今天Chrome不支持FeatureX,但几个月后它开始支持它。如果你简单地说

// Here I detect Chrome browser without a third-party library
if (navigator.userAgent.toLowerCase().indexOf('chrome') === -1) {
    doFeatureX()
else {
    console.log('Sorry, no Feature X for you.')
}
然后你就把Chrome用户永远锁在外面了。你应该这样做,有很多方法可以帮助你:

if (Modernizr.geolocation) {
    // do stuff with user's coordinates
}
当然,如果你愿意,你可以检测浏览器。例如,您希望鼓励人们升级浏览器:

// Here I'm using jQuery
if ($.browser.msie && parseInt($.browser.version, 10) < 9) {
    // show link to http://microsoft.com/ie
} else if ($.browser.mozilla && parseInt($.browser.version, 10) < 11) {
    // show link to http://mozilla.com/firefox
} // etc.

根据你想做什么,你可以用功能检测来代替。来吧,你知道如何在谷歌搜索东西,不是吗?检查javascript6问题中的navigator对象,其中0%的问题有可接受的答案…其信息不正确,它显示了mozzila和netscape o_oHey,它显示了一切。浏览器的详细信息。在使用之前,您必须对其进行操作。