Rv1
Rv1

Reputation: 185

Trouble with Navigator.appCodeName and Useragent

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

Answers (1)

robC
robC

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

Related Questions