How can you detect the version of a browser?

后端 未结 28 2077
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-21 23:35

I\'ve been searching around for code that would let me detect if the user visiting the website has Firefox 3 or 4. All I have found is code to detect the type of browser but

28条回答
  •  广开言路
    2020-11-22 00:27

    In pure Javascript you can do a RegExp match on the navigator.userAgent to find the Firefox version:

    var uMatch = navigator.userAgent.match(/Firefox\/(.*)$/),
        ffVersion;
    if (uMatch && uMatch.length > 1) {
        ffVersion = uMatch[1];
    }
    

    ffVersion will be undefined if not a Firefox browser.

    See working example →

提交回复
热议问题