javascript - Browser version Detection - Stack Overflow

I have a spec in my current project that requires us to advise the user which browsers are best to use

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 badges
Add a ment  | 

4 Answers 4

Reset to default 4

Here 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');
    }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745546391a4632357.html

相关推荐

  • javascript - Browser version Detection - Stack Overflow

    I have a spec in my current project that requires us to advise the user which browsers are best to use

    3天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信