JS

How to get browser’s name using jQuery?

In this blog we will see How to get browser’s name using jQuery?
we will see two way to detect all browser name using jQuery javascript.
First Code for detect Chrome,Firefox,Safari browser.
1. First add this following library:

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

2. Then add this following script in your favourite Editor like Visual studio,Notepad++.

<script>
debugger;
   $(document).ready(function(){
  
    $.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
    
    /* Detect Chrome */
    if($.browser.chrome){
       
        alert("You are using Chrome!");
        
        $.browser.safari = false;
    }
    /* Detect Firefox*/

     if(navigator.userAgent.indexOf("Firefox") != -1 )
      {
             alert('You are Using Firefox');
      }
       
          
      
    /* Detect Safari */
    if($.browser.safari){
        /* Do something for Safari */
        alert("You are using Safari!");
    }
   

});
</script>

Complete Code for How to get browser’s name using jQuery?

<!DOCTYPE html>
<html>
<head>
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.0.0.js"></script>
<script src="https://code.jquery.com/jquery-migrate-1.3.0.js"></script>
<script src="https://code.jquery.com/jquery-migrate-3.0.1.js"></script>
<script>
debugger;
   $(document).ready(function(){
  
    $.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
    
    /* Detect Chrome */
    if($.browser.chrome){
       
        alert("You are using Chrome!");
        
       $.browser.safari = false;
    }
    /* Detect Firefox*/
      if(navigator.userAgent.indexOf("Firefox") != -1 )
      {
             alert('You are Using Firefox');
      }
       
    /* Detect Safari */
    if($.browser.safari){
        /* Do something for Safari */
        alert("You are using Safari!");
    }
   

});
</script>

</head>
<body>

 Find Browser In JQuery

</body>
</html>

Second Code for get browser’s name using jQuery?
Write this code for detect Chrome,Safari,Firefox,IE and other browser.

<!DOCTYPE html>
<html>
<head>
	<title>Browser detector</title>

</head>
<body>
	<input type="button" id="button" value="Click Me" onclick="detectBrowsr()" />

<script>

	function detectBrowsr() { 
        if((navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf('OPR')) != -1 ){
            alert('You are using Opera');
        }
        else if(navigator.userAgent.indexOf("Chrome") != -1 ){
			alert('You are using Chrome');
        }
        else if(navigator.userAgent.indexOf("Safari") != -1){
			alert('You are using Safari');
        }
        else if(navigator.userAgent.indexOf("Firefox") != -1 ){
			alert('You are using Firefox');
        }
        else if((navigator.userAgent.indexOf("msie") != -1 ) || (!!document.documentMode == true )){
          alert('You are Using IE'); 
        }  
		else if((navigator.userAgent.indexOf("chromium") != -1 ) || (!!document.documentMode == true )){
          alert('You are Using IE'); 
        }  
        else{
           alert('unknown');
        }
    }
</script>

</body>
</html>

YouTube Link

Leave a Reply

Your email address will not be published. Required fields are marked *