Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Javascript, how do I determine if my current browser is Firefox on a computer vs everything else?

if(firefox and is on a computer){ alert('using firefox on a computer') }else{ alert("using something else!"); } 

How can I do this?

like image 894
TIMEX Avatar asked Feb 24 '10 09:02

TIMEX


People also ask

How do I identify my browser?

In the browser window, hold the Alt key and press H to bring up the Help menu. Click About Google Chrome and locate the version at the top of the window that appears.

How can you detect the client's browser name in JavaScript?

You can use the navigator. appName and navigator. userAgent properties. The userAgent property is more reliable than appName because, for example, Firefox (and some other browsers) may return the string "Netscape" as the value of navigator.


2 Answers

What you're after is known as browser detection:

if ($.browser.mozilla) { ...  

However, browser sniffing is discouraged, as its easy to spoof the user agent, i.e. pretend to be another browser!

You'd best use feature detection, either in your own way, or through the jQuery.support interface: http://api.jquery.com/jQuery.support/

Here's an article on extending it for your own use: http://www.waytoocrowded.com/2009/03/14/jquery-supportminheight/

Edit:

Found this post as well which helps: When IE8 is not IE8 what is $.browser.version?

like image 102
James Wiseman Avatar answered Sep 22 '22 23:09

James Wiseman


I am doing some thing like below;

function checkBrowser(){     let browser = "";     let c = navigator.userAgent.search("Chrome");     let f = navigator.userAgent.search("Firefox");     let m8 = navigator.userAgent.search("MSIE 8.0");     let m9 = navigator.userAgent.search("MSIE 9.0");     if (c > -1) {         browser = "Chrome";     } else if (f > -1) {         browser = "Firefox";     } else if (m9 > -1) {         browser ="MSIE 9.0";     } else if (m8 > -1) {         browser ="MSIE 8.0";     }     return browser; } 
like image 39
Fayyaz Ali Avatar answered Sep 22 '22 23:09

Fayyaz Ali