js判断是不是chrome浏览器

时间:2022-10-28 06:08:28

方法一:

var isChrome = window.navigator.userAgent.indexOf("Chrome");

 <script>
var isChrome = window.navigator.userAgent.indexOf("Chrome");
if(isChrome !== -1){
console.log(111);
}
else{
console.log(222);
} </script>

方法二:

isChrome == window.google && window.chrome

 <script>
var isChrome;
if(isChrome == window.google && window.chrome){
console.log(111);
}
else{
console.log(222);
}
</script>