In this post, we will learn how to detect browser name using JavaScript. So how we can do this, we will learn in this post.  


How To Detect Browser Name Using JavaScript ?


Detect Browser Name Using JavaScript

Your Browser Name is:

To detect browser name using JavaScript, we use the  navigator  object. This object contains information about the browser. There are many properties of this object. But in this article we will use   navigator.userAgent  property. This property helps us to detect the browser name.


So how we can detect browser name using JavaScript, we will see in the following example.


<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>How To Detect Browser Name Using JavaScript ?</title>
</head>
<body>

<div id="showBrowserName"></div>

<script>

document.getElementById("showBrowserName").innerText = getBrowserName();

function getBrowserName() {
let browserName = navigator.userAgent.toLowerCase();

if(!!document.documentMode == true) {
return "IE";

} else if(browserName.search('opr')> -1) {
return "Opera";

} else if(browserName.search('safari')> -1 && !!window.safari == true) {
return "Safari";

} else if(browserName.search('chrome') > -1 || browserName.search('crios') > -1) {
return "Chrome";

} else if(browserName.search('firefox') > -1 || browserName.search('fxios') > -1 || browserName.search('focus') > -1) {
return "Firefox";

} else {
return "Not Detect Any Browser Name";
}

}

</script>
</body>
</html> code-box


Summary

In this post we learned how to detect browser name using JavaScript. You try to make it yourself. I hope you make. If you face any problem, then comment and tell us. Keep visiting the blog to read more similar posts. 

Post a Comment

Previous Post Next Post