我想检测浏览器是否是Chrome。 我遇到了很多答案,但对于opera和新版Edge来说,所有答案都是真的。 我想知道你有没有最好的方法来检测浏览器是不是chrome
[编辑]到目前为止我测试过的返回true的代码:
null
//Test 1 => Opera and edge returns true
var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
// Test 2 => return false for chrome latest version
var isChrome = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime);
//Test 3 => same as test 1
var is_chrome = /chrome/i.test( navigator.userAgent );
null
答案是你可以使用
navigator.userAgent
然后在结果中寻找“chrome”,看起来像
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36
我使用Navigator.UserAgent作为一种检测移动浏览器上下文的方法,对事件侦听器进行触摸和鼠标操作。
。。。那些认为整个浏览器检测的想法都是错误的人--别开枪! 我只是个信使