- ES6 - Discussion
- ES6 - Useful Resources
- ES6 - Quick Guide
- ES9 - New Features
- ES8 - New Features
- ES7 - New Features
- ES6 - Browsers
- ES6 - Image Map
- ES6 - Debugging
- ES6 - Multimedia
- ES6 - Animation
- ES6 - Validations
- ES6 - Proxy API
- ES6 - Reflect API
- ES6 - Object Extensions
- ES6 - Error Handling
- ES6 - Modules
- ES6 - Promises
- ES6 - Maps And Sets
- ES6 - Classes
- ES6 - Collections
- ES6 - Iterator
- ES6 - HTML DOM
- ES6 - RegExp
- ES6 - Math
- ES6 - Date
- ES6 - Arrays
- ES6 - New String Methods
- ES6 - Symbol
- ES6 - Strings
- ES6 - Boolean
- ES6 - Number
- ES6 - Objects
- ES6 - Page Printing
- ES6 - Void Keyword
- ES6 - Dialog Boxes
- ES6 - Page Redirect
- ES6 - Cookies
- ES6 - Events
- ES6 - Functions
- ES6 - Loops
- ES6 - Decision Making
- ES6 - Operators
- ES6 - Variables
- ES6 - Syntax
- ES6 - Environment
- ES6 - Overview
- ES6 - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
ES6 - Browsers
It is important to understand the differences between different browsers in order to handle each in the way it is expected. So it is important to know which browser your web page is running in. To get information about the browser your webpage is currently running in, use the built-in navigator object.
Navigator Properties
There are several Navigator related properties that you can use in your webpage. The following is a pst of the names and its description.
Sr.No | Property & Description |
---|---|
1 |
appCodeName This property is a string that contains the code name of the browser, Netscape for Netscape and Microsoft Internet Explorer for Internet Explorer. |
2 |
appVersion This property is a string that contains the version of the browser as well as other useful information such as its language and compatibipty. |
3 |
language This property contains the two-letter abbreviation for the language that is used by the browser. Netscape only. |
4 |
mimTypes[] This property is an array that contains all MIME types supported by the cpent. Netscape only. |
5 |
platform[] This property is a string that contains the platform for which the browser was compiled. "Win32" for 32-bit Windows operating systems. |
6 |
plugins[] This property is an array containing all the plug-ins that have been installed on the cpent. Netscape only. |
7 |
userAgent[] This property is a string that contains the code name and version of the browser. This value is sent to the originating server to identify the cpent. |
Navigator Methods
There are several Navigator-specific methods. Here is a pst of their names and descriptions.
Sr.No | Methods & Description |
---|---|
1 |
javaEnabled() This method determines if JavaScript is enabled in the cpent. If JavaScript is enabled, this method returns true; otherwise, it returns false. |
2 |
plugings.refresh This method makes newly installed plug-ins available and populates the plugins array with all new plug-in names. Netscape only |
3 |
preference(name,value) This method allows a signed script to get and set some Netscape preferences. If the second parameter is omitted, this method will return the value of the specified preference; otherwise, it sets the value. Netscape only |
4 |
taintEnabled() This method returns true if data tainting is enabled; false otherwise |
Browser Detection
The following JavaScript code can be used to find out the name of a browser and then accordingly an HTML page can be served to the user.
<html> <head> <title>Browser Detection Example</title> </head> <body> <script type = "text/javascript"> <!-- var userAgent = navigator.userAgent; var opera = (userAgent.indexOf( Opera ) ! = -1); var ie = (userAgent.indexOf( MSIE ) != -1); var gecko = (userAgent.indexOf( Gecko ) ! = -1); var netscape = (userAgent.indexOf( Mozilla ) ! = -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 following output is displayed on successful execution of the above code.
Mozilla based browser Browser version info : 5.0
(Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, pke Gecko) Chrome/41.0.2272.101 Safari/537.36
Advertisements