Home  >  Article  >  Web Front-end  >  What is the role of Navigator object in JavaScript?

What is the role of Navigator object in JavaScript?

王林
王林forward
2023-09-04 23:45:071176browse

What is the role of Navigator object in JavaScript?

#To get information about the browser a web page is currently running in, use the built-in navigator object. You can use various Navigator methods and properties on this object.

Example

You can try running the following code to implement the Navigator object in JavaScript -

<html>
   <head>
      <title>Navigator Object Example</title>
   </head>

   <body>
      <script>
         <!--
            var userAgent = navigator.userAgent;
            var opera = (userAgent.indexOf(&#39;Opera&#39;) != -1);
            var ie = (userAgent.indexOf(&#39;MSIE&#39;) != -1);
            var gecko = (userAgent.indexOf(&#39;Gecko&#39;) != -1);
            var netscape = (userAgent.indexOf(&#39;Mozilla&#39;) != -1);
            var version = navigator.appVersion;
           
            if (opera) {
               document.write("Opera based browser");
               // Keep your opera specific URL here.
            }
            else if (gecko) {
               document.write("Mozilla based browser");
               // Keep your gecko specific URL here.
            }
            else if (ie) {
               document.write("IE based browser");
               // Keep your IE specific URL here.
            }
            else if (netscape) {
               document.write("Netscape based browser");
               // Keep your Netscape specific URL here.
            } else {
               document.write("Unknown browser");
            }
            // You can include version to along with any above condition.
            document.write("<br /> Browser version info : " + version );
         //-->
      </script>
   </body>
</html>

The above is the detailed content of What is the role of Navigator object in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete