1

Actually, When I am using navigator.userAgent.toLowerCase(), I get output like this :

Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36

I don't want this output. But I want to get only current browser name on which I am browsing and get browser name using Jquery. Is there any function to get only current browser name instead of getting all browser names. And, I get output "Chrome" when I am browsing on Google Chrome browser and, Firefox when I am browsing using Firefox Browser. Thanks in advance.

5
  • 2
    May i ask why would you need to know the current browser name? Usually, browser detecting is bad idea Commented Apr 11, 2016 at 11:25
  • Actually I want to show mp4 on firefox which is not work but i have equivalent gif images so When page opens at chrome i will show mp4 and when the same page opens in firefox i will show gif image which is actually converted from the mp4. Commented Apr 11, 2016 at 11:28
  • So you are looking for feature detection instead because anyway in the future FF could support mp4 format). See maybe stackoverflow.com/questions/3572113/… Commented Apr 11, 2016 at 11:29
  • Actually, I have tested that above code give by you but is always gives the output true Commented Apr 11, 2016 at 11:36
  • Already has solution on Stack overflow click here Commented Mar 21, 2017 at 9:33

2 Answers 2

3

Try with this:

Object.keys(jQuery.browser)[0]

Before you used this you must be load this jquery

<script src="https://code.jquery.com/jquery-migrate-1.3.0.js"></script>

because jQuery.browser Will not work in jQuery 1.9 or later unless the jQuery Migrate plugin is included.

Sign up to request clarification or add additional context in comments.

4 Comments

This works for chrome and firefox only but when this code runs on opera then it will give result chrome
It works for all browsers except opera. In opera, output is chrome.
Can I know that particular mp4 is playable or not in browser using javascript or jqyery
Please check this for opera :stackoverflow.com/questions/1998293/…
1

You can search for browser like this:

// Check for Chrome
  if ($.browser.chrome) {
    alert("This is Chrome!");
  }
// Check for IE
  else if($.browser.msie)){
    alert("This is Internet Explorer!");
  }
// Check for Safari
  else if($.browser.safari)){
    alert("This is Safari!");
  }

5 Comments

No for jq before 1.9
I am still on the same starting point I don't get any kind of clue. Actually I want single browser name which is in currently use instead of browser list.
why not using javascript, it is very easy in javascript.
so tell me in js or in jquery there is no problem I need a solution for that
If I added the code for opera in above code like this : if ($.browser.opera) { alert("This is Opera!"); } Then, I also get output chrome instead of opera

Your Answer

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.