Tuesday, May 28, 2024
 Popular · Latest · Hot · Upcoming
121
rated 0 times [  124] [ 3]  / answers: 1 / hits: 175042  / 11 Years ago, mon, october 14, 2013, 12:00:00

I want to detect if the user is using IE and Firefox but I cannot find the script.



I have code as below:



$(document).ready(function(e) {
$.browser.chrome = /chrom(e|ium)/.test(navigator.userAgent.toLowerCase());
if($.browser.chrome){
alert(1);
//this work well
}
else if(//the browser is IE){alert(2);}
else if(//the browser is Firefox){alert(3);}

//The problem is that I don't know how to write a script for IE and FireFox browser for chrome is work fine
)};

More From » jquery

 Answers
11

The best solution is probably: use Modernizr.



However, if you necessarily want to use $.browser property, you can do it using jQuery Migrate plugin (for JQuery >= 1.9 - in earlier versions you can just use it) and then do something like:



if($.browser.chrome) {
alert(1);
} else if ($.browser.mozilla) {
alert(2);
} else if ($.browser.msie) {
alert(3);
}


And if you need for some reason to use navigator.userAgent, then it would be:



$.browser.msie = /msie/.test(navigator.userAgent.toLowerCase()); 
$.browser.mozilla = /firefox/.test(navigator.userAgent.toLowerCase());

[#75011] Saturday, October 12, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
raveno

Total Points: 453
Total Questions: 92
Total Answers: 92

Location: France
Member since Thu, Oct 27, 2022
2 Years ago
raveno questions
;