admin管理员组文章数量:1430093
I have a spec in my current project that requires us to advise the user which browsers are best to use the web application. If their current browser version they are using is not in our list of "ideal" browsers we want to display a message.
What is the best way to check a specific version of the users browser. I am aware of the following using jQuery but this doesn't help with specific versions.
$(document).ready(function() {
var b = '';
$.each($.browser, function(i, val) {
if (i=='safari' && val==true) { b = 'safari'; }
if (i=='opera' && val==true) { b = 'opera'; }
if (i=='msie' && val==true) { b = 'msie'; }
if (i=='mozilla' && val==true) {b = 'mozilla'; }
});
//Do Something With b, Like $('#dis').html(b);
});
We want to be able to say is your browser Firexfox 2 or greater or IE6 or greater etc?
I have a spec in my current project that requires us to advise the user which browsers are best to use the web application. If their current browser version they are using is not in our list of "ideal" browsers we want to display a message.
What is the best way to check a specific version of the users browser. I am aware of the following using jQuery but this doesn't help with specific versions.
$(document).ready(function() {
var b = '';
$.each($.browser, function(i, val) {
if (i=='safari' && val==true) { b = 'safari'; }
if (i=='opera' && val==true) { b = 'opera'; }
if (i=='msie' && val==true) { b = 'msie'; }
if (i=='mozilla' && val==true) {b = 'mozilla'; }
});
//Do Something With b, Like $('#dis').html(b);
});
We want to be able to say is your browser Firexfox 2 or greater or IE6 or greater etc?
Share Improve this question edited Jan 9, 2009 at 11:20 Oli 240k67 gold badges226 silver badges304 bronze badges asked Jan 9, 2009 at 10:15 SheffSheff 3,4823 gold badges35 silver badges35 bronze badges4 Answers
Reset to default 4Here is a JQuery plugin that'll help
Also check for $.browser.version in the docs.jquery.
It can return 2.0 for Firefox 2.x.x, check the docs :)
Check out the YUI User-Agent Detection.
EDIT: Now that I've told you how, I just want to make sure you know that this is generally considered an antipattern, right? If you can, I'd remend not doing something like this, but I realize that's not always an option.
Internet Explorer 10 and above versions behave differently from IE 9 and below. When using javascript you need to handle those scenarios differently. Following code worked for me :)
//MSStream object supported only for IE 10 and 11 (hope this will work for above IE 11 too .. )
var isIE10or11 = window.MSStream;
//FormData object allow you to send form data as key and value pairs with ajax requests. Supported in modern browsers.
var isFormDataSupported = (window.FormData !== undefined);
if(isIE10or11 && isFormDataSupported){
alert('IE 10 or 11');
}
else if(!isIE10or11 && isFormDataSupported){
alert('HTML 5 browser Excluding IE');
}
else{
//Neither supports MSStream nor FormData object
alert('IE Version 9 or below');
}
本文标签: javascriptBrowser version DetectionStack Overflow
版权声明:本文标题:javascript - Browser version Detection - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745546390a2662723.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论