开发者

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

I would like to show a pop-up telling the user if 开发者_如何学JAVAtheir browser is outdated. How can I find out what browser they are using in javascript?


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.


Check out this browser detection script:

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


Don't detect browsers, detect browser features. There's a good discussion on Stack Overflow already:

Browser detection versus feature detection

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜