[removed] How to find out if the user browser is Chrome?

后端 未结 15 1545
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 09:41

I need some function returning a boolean value to check if the browser is Chrome.

How do I create such functionality?

15条回答
  •  盖世英雄少女心
    2020-11-22 10:19

    If you're feeling brave, you can experiment with browser sniffing and get a version:

    var ua = navigator.userAgent;
    if(/chrome/i.test(ua)) {
        var uaArray = ua.split(' ')
        ,   version = uaArray[uaArray.length - 2].substr(7);
    }
    

    This detected version might be a Chrome version, or a Edge version, or something else. Browser plugins can easily change userAgent and platform and other things though, so this is not recommended.

    Apologies to The Big Lebowski for using his answer within mine.

提交回复
热议问题