3

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?

Oli
241k68 gold badges227 silver badges305 bronze badges
asked Jan 9, 2009 at 10:15

4 Answers 4

4

Here is a JQuery plugin that'll help

answered Jan 9, 2009 at 11:03
Sign up to request clarification or add additional context in comments.

Comments

4

Also check for $.browser.version in the docs.jquery.com

It can return 2.0 for Firefox 2.x.x, check the docs :)

answered Jan 9, 2009 at 10:43

Comments

2

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 recommend not doing something like this, but I realize that's not always an option.

answered Jan 9, 2009 at 10:19

2 Comments

Thanks for that but I'm not sure how the YUI detection differers from the JQuery example I gave? It still doesn't get the browser version eg Firefox 3.0.5. It only returns Firefox. It would also be best if we could use the JQuery library of standard JavaScript as that is what we are already using.
I'm pretty sure it returns a version number, not a simple boolean.
0

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');
 }
answered Feb 5, 2015 at 8:34

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.