如何使用jQuery检测浏览器是否是Chrome? [英] How to detect if a browser is Chrome using jQuery?

查看:44
本文介绍了如何使用jQuery检测浏览器是否是Chrome?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Chrome 中运行的一个功能在 Safari 中正常运行时遇到了一些问题,两个 webkit 浏览器...

I have a bit of an issue with a function running in chrome that works properly in Safari, both webkit browsers...

我需要在 Chrome 的函数中自定义一个变量,而不是 Safari.

I need to customize a variable in a function for Chrome, but not for Safari.

遗憾的是,我一直在使用它来检测它是否是 webkit 浏览器:

Sadly, I have been using this to detect if it is a webkit browser:

if ($.browser.webkit) {

但我需要检测:

if ($.browser.chrome) {

有没有什么办法可以写出类似的语句(上述语句的工作版本)?

Is there any way to write a similar statement (a working version of the one above)?

推荐答案

$.browser.chrome = /chrom(e|ium)/.test(navigator.userAgent.toLowerCase()); 

if($.browser.chrome){
  ............

}

更新:(10 倍于@Bacciagalupe 先生)

jQuery 已从 1.9 及其最新版本中删除了 $.browser.

jQuery has removed $.browser from 1.9 and their latest release.

但是你仍然可以使用 $.browser 作为一个独立的插件,在 here

But you can still use $.browser as a standalone plugin, found here

这篇关于如何使用jQuery检测浏览器是否是Chrome?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆