This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

  • 15.5 JS Navigator

    The window.navigator object contains information about the visitor's browser.

    Window Navigator

    • The window.navigator object can be written without the window prefix.
    • Some examples:
      • navigator.cookieEnabled
      • navigator.appCodeName
      • navigator.platform

    Browser Cookies

    The cookieEnabled property returns true if cookies are enabled, otherwise false:

    Example 1: JS Navigator Object - Browser Cookies
    <p id="demo"></p>
    
    <script>
    document.getElementById("demo").innerHTML =
    "cookiesEnabled is " + navigator.cookieEnabled;
    </script> 

    Browser Application Name

    The appName property returns the application name of the browser:

    Example 2: JS Navigator Object - Browser Application Name
    <p id="demo"></p>
    
    <script>
    document.getElementById("demo").innerHTML =
    "navigator.appName is " + navigator.appName;
    </script>
    • Warning
    • This property is removed (deprecated) in the latest web standard.
    • Most browsers (IE11, Chrome, Firefox, Safari) returns Netscape as appName.

    Browser Application Code Name

    The appCodeName property returns the application code name of the browser:

    Example 3: JS Navigator Object - Browser Application Code Name
    <p id="demo"></p>
    
    <script>
    document.getElementById("demo").innerHTML =
    "navigator.appCodeName is " + navigator.appCodeName;
    </script>
    • Warning
    • This property is removed (deprecated) in the latest web standard.
    • Most browsers (IE11, Chrome, Firefox, Safari, Opera) returns Mozilla as appCodeName.

    The Browser Engine

    The product property returns the product name of the browser engine:

    Example 4: JS Navigator Object - The Browser Engine
    <p id="demo"></p>
    
    <script>
    document.getElementById("demo").innerHTML =
    "navigator.product is " + navigator.product;
    </script>
    • Warning
    • This property is removed (deprecated) in the latest web standard.
    • Most browsers returns Gecko as product.

    The Browser Version

    The appVersion property returns version information about the browser:

    Example 5: JS Navigator Object - The Browser Version
    <p id="demo"></p>
    
    <script>
    document.getElementById("demo").innerHTML = navigator.appVersion;
    </script>

    The Browser Agent

    The userAgent property returns the user-agent header sent by the browser to the server:

    Example 6: JS Navigator Object - The Browser Agent
    <p id="demo"></p>
    
    <script>
    document.getElementById("demo").innerHTML = navigator.userAgent;
    </script>

    Warning

    • The information from the navigator object can often be misleading.
    • The navigator object should not be used to detect browser versions because:
      • Different browsers can use the same name
      • The navigator data can be changed by the browser owner
      • Some browsers misidentify themselves to bypass site tests
      • Browsers cannot report new operating systems, released later than the browser

    The Browser Platform

    The platform property returns the browser platform (operating system):

    Example 7: JS Navigator Object - The Browser Platform
    <p id="demo"></p>
    
    <script>
    document.getElementById("demo").innerHTML = navigator.platform;
    </script>

    The Browser Language

    The language property returns the browser's language:

    Example 8: JS Navigator Object - The Browser Language
    <p id="demo"></p>
    
    <script>
    document.getElementById("demo").innerHTML = navigator.language;
    </script>

    Is The Browser Online?

    The onLine property returns true if the browser is online:

    Example 9: JS Navigator Object - Is The Browser Online?
    <p id="demo"></p>
    
    <script>
    document.getElementById("demo").innerHTML = navigator.onLine;
    </script>

    Is Java Enabled?

    The javaEnabled() method returns true if Java is enabled:

    Example 10: JS Navigator Object - Is Java Enabled?
    <p id="demo"></p>
    
    <script>
    document.getElementById("demo").innerHTML = navigator.javaEnabled();
    </script>
    Navigate this module

    Eventually the navigation links, above, will be replaced by these << (previous) and >> (next) buttons below.



    JavaScript icons used in the buttons provided by ICONS8.COM. Smartphone icons created by Freepik - Flaticon