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.

Saurabh Aren
  • 23
  • 1
  • 1
  • 11
  • 2
    May i ask why would you need to know the current browser name? Usually, browser detecting is bad idea – A. Wolff Apr 11 '16 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. – Saurabh Aren Apr 11 '16 at 11:28
  • So you are looking for feature detection instead because anyway in the future FF could support mp4 format). See maybe http://stackoverflow.com/questions/3572113/how-to-check-if-the-browser-can-play-mp4-via-html5-video-tag – A. Wolff Apr 11 '16 at 11:29
  • Actually, I have tested that above code give by you but is always gives the output true – Saurabh Aren Apr 11 '16 at 11:36
  • Already has solution on Stack overflow [click here](http://stackoverflow.com/questions/19352522/how-can-i-detect-browser-type-using-jquery) – Himanshu Sharma Mar 21 '17 at 09:33

2 Answers2

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.

Bhavesh Odedra
  • 10,990
  • 12
  • 33
  • 58
Pravin Tukadiya
  • 489
  • 4
  • 20
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!");
  }
Sumanta736
  • 695
  • 3
  • 10