admin管理员组文章数量:1326478
With all these api changes in jquery, what is the 'latest' best practice to detect browser name and version in jQuery?
Also, is jquery the remended language to detect browsers or should I use server-side?
With all these api changes in jquery, what is the 'latest' best practice to detect browser name and version in jQuery?
Also, is jquery the remended language to detect browsers or should I use server-side?
Share Improve this question asked Jul 13, 2011 at 4:52 Pablo SantiagoPablo Santiago 554 bronze badges 1- "Best practice" for browser detection is not to do it at all. – RobG Commented Jul 13, 2011 at 5:13
6 Answers
Reset to default 3You want to avoid browser detection & instead do feature detection.browser detection can be easily faked & therefore is unreliable. see a nice post by John Resig on this subject.
for more details, Google for "Browser detection versus feature detection"
The 'best practice' to detect a browser using jQuery is with jQuery.support:
http://api.jquery./jQuery.support/
However if for whatever reason you actually need to know the specific browser, rather than whether a feature is supported, jquery does have a browser detection using the user-agent:
http://api.jquery./jQuery.browser/
As mentioned on that page however, this is not remended and may be moved to a plugin in a future version of jQuery.
$.browser
is easy by not as remended any more.
http://api.jquery./jQuery.browser/
Remember, it's trivial to fake your user agent and I don't believe it's possible to any more reliably detect browsers server-side. Just don't use detection for anything super critical.
jQuery instead suggests you detect for specifically the reasons why you're checking for browsers in the first place.
For example if (jQuery.support.boxModel) ....
http://api.jquery./jQuery.support/
jQuery.browser works well. in most cases all methods will look up the browser agent text, which can be changed by the user, so there is no sure-fire method.
they remend not using this and to check for the presence of specific APIs, but if you need to know the browser this method works well.
jQuery.each(jQuery.browser, function(i, val) {
$("<div>" + i + " : <span>" + val + "</span>")
.appendTo( document.body );
});
you can refer refer
HTML5, CSS needs, use Modernizr (http://modernizr./)
$.support or $.browser are limited.
本文标签: javascriptjQuery 16 Browser detectionStack Overflow
版权声明:本文标题:javascript - jQuery 1.6 Browser detection - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742207980a2433175.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论