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

后端 未结 15 1714
伪装坚强ぢ
伪装坚强ぢ 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:18

    If you want to detect Chrome's rendering engine (so not specific features in Google Chrome or Chromium), a simple option is:

    var isChrome = !!window.chrome;
    

    NOTE: this also returns true for many versions of Edge, Opera, etc that are based on Chrome (thanks @Carrm for pointing this out). Avoiding that is an ongoing battle (see window.opr below) so you should ask yourself if you're trying to detect the rendering engine (used by almost all major modern browsers in 2020) or some other Chrome (or Chromium?) -specific feature.

    And you can probably skip !!

提交回复
热议问题