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

detect browser javascript
javascript detect browser version
detect safari browser
user agent device detection
user agent mobile detection
angular detect browser
detect mobile browser
javascript user agent detection
if(firefox and is on a computer){
alert('using firefox on a computer')
alert("using something else!");

How can I do this?

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 interface:

Here's an article on extending it for your own use:


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

Browser detection using the user agent, The Web is meant to be accessible to everyone, regardless of which People use user agent sniffing to detect if the users' device is fallback } else { // Only as a last resort, fall back to user agent sniffing var UA = navigator. That will only annoy people because it will force them to use the desktop version. Any solutions that are mentioned here are not safe because the agent does not always provide the correct browser name in the first place. If you call a page with chrome you also have safari in the agent.

I am doing some thing like below;

function checkBrowser(){
    c ="Chrome");
    f ="Firefox");
    m8 ="MSIE 8.0");
    m9 ="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;

Window.navigator, The Window.navigator read-only property returns a reference to the Navigator object, which Example #1: Browser detect and return a string. How to Use JavaScript to Detect Browser at Learning jQuery. Wouldn't it be nice if all of our code looked the same and worked the same no matter what browser our users are viewing our projects or web pages on?

Like this: Check for Firefox. Or some other browser.

 window.onload = function() {
          //  alert(navigator.userAgent);
            if (navigator.userAgent.indexOf("Firefox") > 0) {

Handling common JavaScript problems, These days, most cross-browser JavaScript problems are seen: First of all, we know that the error is being thrown at line 51. before code that relies on their results is used for something else. Note: This is called "transpiling" — you are not compiling code into a lower level to be run on a computer (like  It's often important to know what version of Firefox you are using, to help you troubleshoot a problem or just to know if Firefox is up to date. Here are two ways to find out. Click the menu button , click Help and select About Firefox. On the menu bar, click the Firefox menu and select About Firefox. The About Firefox window will appear.

if (navigator.userAgent.indexOf("Firefox") != -1) {

 //some specific code for Mozilla


Browser Detection and Cross Browser Support, If you must determine if a visitor is using a Gecko-based browser, simply test Although many web developers are aware of Firefox, Mozilla, and Netscape Netscape Navigator 2 introduced the ability to run JavaScript in web browsers. WRONG APPROACH - do not use! if (document.all) { // Internet  How to enable JavaScript in your browser Nowadays almost all web pages contain JavaScript, a scripting programming language that runs on visitor's web browser. It makes web pages functional for specific purposes and if disabled for some reason, the content or the functionality of the web page can be limited or unavailable.

navigator.sayswho= (function(){
  var N= navigator.appName, ua= navigator.userAgent, tem;
  var M= ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i);
  if(M && (tem= ua.match(/version\/([\.\d]+)/i))!= null) M[2]= tem[1];
  M= M? [M[1], M[2]]: [N, navigator.appVersion,'-?'];
  return M.join(' ');

as the name suggests, this is who the browser says it is- but use object detection before asking it to actually do anything...

I use it for logging errors from users and in testing code in multiple browsers- where I know the userAgent strings.

Navigator.onLine, In Firefox and Internet Explorer, switching the browser to offline mode sends a false value. Until Firefox 41, all other conditions return a true value;  What browser am I using? What version is my browser? is the easiest way to find information about your browser, and share it to your designer, developer, or support rep.

How to detect the user browser ( Safari, Chrome, IE, Firefox and , How to detect the user browser ( Safari, Chrome, IE, Firefox and Opera ) using JavaScript ? The browser on which the current page is opening can be checked using JavaScript. If the value does not come up in the string, “-1” is returned. This is done for all the following tests. and Opera browser using JavaScript? We pit Chrome, Firefox, Opera, Microsoft Edge, and Vivaldi against one another to determine the best browsers for 2020. There are a few great alternatives too.

The Modern Web: Multi-Device Web Development with HTML5, CSS3, and , Multi-Device Web Development with HTML5, CSS3, and JavaScript Peter Layout, Regions, and Exclusions), but everything else is proceeding apace. Instead, in this appendix, I'll stick to the key modern desktop browsers—Chrome, Firefox, As this book was going to press, Opera announced that it would be phasing  What browser am I using? Is my browser up to date? Find these things out and more! Including JavaScript, Cookie, Local IP address, Flash, and Java detection.

Practical JavaScript, DOM Scripting and Ajax Projects, tests were run on the same PC, without virtual machines or anything like that. So the difference is attributable to the browsers almost entirely. But I actually went so far as to reboot before running each test and didn't load anything else, so it In fact, a great many web developers will tell you that Firefox is superior, yet  Firefox is now listed as your default browser. Close the Settings window to save your changes. Use the Settings app in Windows 10 to change your default browser. Alternatively, you can open the Settings App from the Windows 10 Start menu to set Firefox as the default browser: Go to the Windows Start menu and click the Settings icon.

  • What does "is on a computer mean" ? Do you want to also detect iphones and other mobile deveices ?
  • Why do you want to know that?
  • because the q says if firefox AND is on a computer ? The is on a computer must be important otherwise it wouldnt be there.. after all its redundant otherwise.
  • You mean discouraged? ;) +1 for feature detection, please do it 'the right way':…
  • @Marcel Korpel: Brilliant article, by the way. I realised that I didn't properly understand feature detection. Have you posted that in an answer? Because I'd happily vote it up!
  • I don't agree with your "the right way". Spoofing the user agent is not done for evil purpose, but to workaround developer bugs. So it's better trust what user wants you think he is.. he has better reason than you
  • This is depreciated and removed from the latest jQuery
  • It outputs: "TypeError: $.browser is undefined", because this property was removed from latest versions of jQuery.
  • You're introducing global variables, and this does not look like a robust way to check this. For instance, this detects Edge as "Chrome"
  • this property was removed from jQuery
  • It'd be nice if this always worked. But sometimes you have a case where features are implemented slightly differently in different browsers, but this difference isn't declared in a variable. For instance, I'm trying to deal with the problem that you can't copy text from disabled fields in firefox, but you can in every other browser. So I need to switch to using the readOnly attribute in firefox. There's no way to detect this other than knowing the user agent.
  • While this code may answer the question but adding an explanation of the code would be helpful to future readers.
  • Pretty much everything includes the string Mozilla … including Safari on the iPhone! This is useless for determining if Firefox is being used, it is useless for determining if a computer is being used!
  • Have a look at for a detailed history of the infamous Mozilla tag.