为什么$ .browser德precated - 什么是更好的选择吗? [英] Why is $.browser deprecated - and what is a better alternative?

查看:330
本文介绍了为什么$ .browser德precated - 什么是更好的选择吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我知道 $。浏览器已去precated和皱眉的,因为jQuery的1.3,但它仍然存在和放大器;在code工作。

So I know $.browser has been deprecated and "frowned upon", since jQuery 1.3, but it continues to exist & work in the code.

它依然采用了普通的JavaScript:的navigator.userAgent 来确定所使用的浏览器,以及版本。

It's still using the plain javascript: navigator.userAgent to determine the browser being used, as well as the version.

现在是有什么关于这些我不知道自己导航,我不应该用或者 $。浏览器或纯香草JS获得的浏览器/版本的?我只是想确保,当他们有IE8(例如),但它们的确拥有它,而且我不处理错误code。

Now is there something about these I don't know about navigator itself, that I shouldn't be using either $.browser or plain vanilla JS to get the browser/version? I just want to make sure when they have IE8 (for example), they really do have it, and I'm not processing the wrong code.

什么其他替代我们对浏览器嗅探?我知道 $。支持,我用 Modernizr的,但有时我只需要需要而不是看到什么浏览器能够处理的降浊浏览器版本,(我认为这是一个完全不同的问题解决者)。

What other alternatives do we have for browser sniffing? I know about $.support, I use modernizr, but sometimes I need just need the down and dirty browser version, instead of seeing what the browser is capable of handling (I think that is a completely different problem solver).

推荐答案

您样的回答自己的问题。理想的是检查功能的支持。随着越来越多的浏览器和设备进入市场这种做法应该扩展。

You kind of answer the question yourself. The ideal is to check for feature support. As more browsers and devices come onto the market this approach should scale.

然而,如果你想要做的事下来,脏当然作品,那么浏览器检测,但只只要你就会知道在现有的浏览器设置你的code ++工程(甚至只是那些你已经测试你的code用)。

However if you want to do something 'down and dirty' then browser detection of course works, but only so far as you will know your code works in the existing set of browsers (or even just those you've tested your code with).

这篇关于为什么$ .browser德precated - 什么是更好的选择吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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