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

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

问题描述



我需要自定义一个变量



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

  if($ .browser.webkit){

但我需要检测:

  if($ .browser.chrome){

有没有办法写一个类似的语句(上面的工作版本)?

解决方案

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

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

}

UPDATE:(10x to @Mr。Bacciagalupe)



jQuery已从 1.9 及其最新版本中移除 $。browser



但您仍然可以使用$ .browser作为独立插件,这里


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

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

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

if ($.browser.webkit) {

But I need to detect:

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){
  ............

}

UPDATE:(10x to @Mr. Bacciagalupe)

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

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

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

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