文件输入标签点击(Firefox)的解决方法 - jQuery 1.9

时间:2013-02-19 16:38:06

标签: javascript jquery firefox input label

首先,这非常类似于: Workaround for file input label click (Firefox)

但是提供的解决方案在jQuery 1.9 +

中无效

$ .browser变量不再存在,因为现在我们必须feature detection

我非常想检测我需要的功能但是jQuery中似乎没有这样的支持。 浏览器检测消失了,功能检测似乎无法检测到我需要的东西,那里有一个很好的解决方案吗? Modernizr解决方案也将受到赞赏,并且普通的vanilla-js解决方案也被接受

感谢您的帮助。

2 个答案:

答案 0 :(得分:3)

if ( window.mozIndexedDB !== undefined ) {
   //do firefox things
}

这只会在Firefox中返回true,afaik。

示例测试:

if ( window.mozIndexedDB !== undefined ) {
   alert('You are using Firefox');
}

您可以尝试查看window.navigator.userAgent但我不推荐它,其他一些浏览器标识为Mozilla,请参阅此问题以获取一些示例:Why Does “navigator.userAgent” in javaScript returns the String “Mozilla” when tried in a google chrome borwser?

答案 1 :(得分:0)

不是最佳做法,但为什么不试试jQuery Migrate plugin?它带回了$ .browser,以及其他一些删除的功能。

相关问题