Browser compatibility in JavaScript

It is extremely important to understand the differences between different web browsers to handle each one in the best way. Therefore, you must know which browser your website is running from so that it can provide a suitable solution.

The available navigator object will help identify information about the browser that the website is currently running on.

Properties of Navigator

There are several Navigator-related properties that you can use in your website. Below are the Navigator properties and detailed descriptions of them.

Attribute appCodeName description

This attribute is a string that contains the browser code name, like Netscape for Netscape and Microsoft Internet Explorer for IE.

appVersion

This property is a string that contains the browser version as well as other useful information such as language and its compatibility.

language

This property contains two abbreviations for the language that is used by the browser. Only for Netscape.

mimTypes []

This property is an array containing all MIME types supported by the Client. Only for Netscape.

platform []

This property is a string containing the platform on which the browser is compiled. "Win32" for Windows 32 bit OS.

plugins []

This property is an array containing all plug-ins installed on the client. Only for Netscape.

userAgent []

This property is a string that contains the code name and version of the browser. This value is sent to the Source Server to identify the Client.

Navigator methods

Below is a list of Navigator methods and detailed description of them:

javaEnabled (): This method determines if JavaScript is enabled in the Client. If JavaScript is enabled, this method returns true, otherwise it returns false.

plugings.refresh: This method creates the latest installed plug-in and places plugins with all new plug-in names. Only for Netscape.

preference (name, value): This method allows a script to be marked to receive and set a number of Netscape preferences. If the second parameter is omitted, this method returns the value of the specified priority; otherwise, it sets that value. Only for Netscape.

taintEnabled (): This method returns true if corrupted data (data tainting) is enabled; otherwise false.

Check the browser (Browser Detection)

This is a simple JavaScript code that can be used to find the name of a browser and then send the HTML page that matches that browser to the user.

 Browser Detection Example  type = "text/javascript" >  

Result

 Mozilla based browser 
Browser version info: 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit / 537.36
(KHTML, like Gecko) Chrome / 67.0.3396.99 Safari / 537.36

According to Tutorialspoint

Previous article: Image Map in JavaScript

Next post: What is HTTP

4 ★ | 2 Vote

May be interested

  • Things to know about 'this' in JavaScriptThings to know about 'this' in JavaScript
    are you having trouble understanding the keyword 'this' in javascript ? then please read what you need to know about 'this' in javascript below.
  • Udemy's top 5 JavaScript coursesUdemy's top 5 JavaScript courses
    a programming language that runs on any computer in the world. a language does not need any special software to run. a language ranked among the top in the world.
  • JavaScript code to generate box and whisker charts/graphsJavaScript code to generate box and whisker charts/graphs
    the example below illustrates a box and whisker chart/graph template created with javascript. the article also provides the source code for you to edit in the browser and save to your computer to run locally.
  • Top site with many good JavaScript exercises to practiceTop site with many good JavaScript exercises to practice
    many people, after taking javascript courses and being equipped with some knowledge of the language they pursue, are eager to improve and cultivate these learned skills. so this article will give you a list of the top 3 websites to actually make javascript.
  • What is JavaScript?What is JavaScript?
    javascript is a programming language of html and web. it is lightweight and most commonly used as part of web pages, but their implementation allows client-side scripts to interact with users and create dynamic websites. it is an interpreted programming language with object-oriented capabilities.
  • How to Enable Cookies and JavaScriptHow to Enable Cookies and JavaScript
    this article shows you how to enable cookies and javascript in your web browser. cookies are pieces of data from visited websites that browsers store to make re-visiting and using those websites quicker and more personal. javascript is a computer language that allows browsers to load and display some eye-catching things on web pages. remember that if left on by default, javascript is usually enabled on most browsers.
  • ! = and! == What is the difference in JavaScript?! = and! == What is the difference in JavaScript?
    javascript includes operators like in other languages. an operator performs some operations on one or more operands (data values) and produces a result. today's article will help readers learn about 2! = and! == operators in javascript.
  • JavaScript code to create bubble chart with custom markerJavaScript code to create bubble chart with custom marker
    the example below shows a bubble chart with a customized highlight style and javascript source code that you can edit in your browser or save to your device to run locally.
  • Learn about ES6 in JavascriptLearn about ES6 in Javascript
    es6 refers to version 6 of the ecma script programming language. ecma script is the standard name for javascript and version 6 is the next version after version 5, released in 2011.
  • Enable JavaScript in browsersEnable JavaScript in browsers
    all modern browsers come with support available for javascript. often, you may need to manipulate to enable or disable this support. this chapter explains the procedure to enable and disable javascript support in your browser: internet explorer, firefox, chrome, and opera.