简体   繁体   English

如何找出用户使用的浏览器?

[英]How can I find out which browser a user is using?

I would like to show a pop-up telling the user if their browser is outdated. 我想显示一个弹出窗口,告诉用户他们的浏览器是否已过时。 How can I find out what browser they are using in javascript? 如何在javascript中找出他们使用的浏览器?

Check out this browser detection script: 查看此浏览器检测脚本:

http://www.quirksmode.org/js/detect.html http://www.quirksmode.org/js/detect.html

function BrowserDetection() {

        if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {

            var ffversion = new Number(RegExp.$1) ;     
        }

        else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {

            var ieversion = new Number(RegExp.$1);       
        }

        else if (/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
            var chromeversion = new Number(RegExp.$1);
            // capture x.x portion and store as a number

        }
        else if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {

            var oprversion = new Number(RegExp.$1) 
        }
        else if (/Safari[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
            var safariversion = new Number(RegExp.$1);


        }

        }

Then after finding the version, u will compare and display popup according to your need. 然后在找到版本后,您将根据需要比较并显示弹出窗口。

Don't detect browsers , detect browser features . 不检测浏览器 ,检测浏览器功能 There's a good discussion on Stack Overflow already: 已经对Stack Overflow进行了很好的讨论:

Browser detection versus feature detection 浏览器检测与特征检测

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用JavaScript在浏览器中找到websocket-protocol版本? - How can I find out the websocket-protocol version in a Browser using javascript? 如何找到打开子窗口或父窗口的窗口,以防止复制URL并在浏览器的其他页面中使用它 - how can I find which window is open child or Parent to prevent copying of URL and using it in a different page of the browser JavaScript:如何确定用户浏览器是否为 Chrome? - JavaScript: How to find out if the user browser is Chrome? 我可以在浏览器中找出配色方案吗 - Can I find out the color scheme in the browser 如何找出正在调用的函数? - How can I find out which functions are being called? 如何找出哪个Javascript导致Ajax请求? - How can I find out which Javascript causes an Ajax request? 如何找出哪个JS文件重新路由URL? - How can I find out which JS file is rerouting URLs? 如何找出调用了哪个Javascript函数? - How can I find out which Javascript function was invoked? 如何找到用户的城市,年龄和性别? - How can I find out the user's city, age and gender? 如何使用JavaScript找出登录用户的域? - How do I find out the domain of logged on user using JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM