Reputation: 185
While executing below code it was displaying Mozilla eventhough if it was executed in safari or chrome at Useragent and AppCode Name. Am i missing anything?
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display the code name of your browser.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<p id="demo1"></p>
<script>
function myFunction() {
var x = "Browser CodeName: " + navigator.appCodeName;
var y = navigator.userAgent;
document.getElementById("demo").innerHTML = x;
document.getElementById("demo1").innerHTML = y;
}
</script>
</body>
</html>
Upvotes: 0
Views: 177
Reputation: 2747
navigator.appCodeName
always returns 'Mozilla' on any browser because the property is deprecated and kept only for compatibility purposes.
https://developer.mozilla.org/en-US/docs/Web/API/NavigatorID.appCodeName
A library like https://github.com/ded/bowser will solve the problem for most browser detection.
This library is more exhaustive: https://github.com/bestiejs/platform.js/
Upvotes: 1