Skip to main content

How to check if JavaScript is enabled and Use of NAVIGATOR Object in javascript

 

Episode#3 Topics:-

  • Why NoScript tag important? How to use this tag? 
  • What is a navigator in javascript? How to use this?
  • Example to know browser properties.
  • Example to know flash player installed or not in your system.
  • Example to know your location in javascript.







If u r making a website with the help of javascript, u must use  <noscript></noscript>


Why it's important to use the NoScript tag by developers?


  • Website users will not be allowed to use features made by JS code.
  • It may decrease no of users on your website
  • It may prevent you from attack. like you made a form where all validations added/written in javascript. so in this case your validation will fail.

Navigator object:- 

Navigator in JavaScript is an object that provides details about the browser that the user uses to access the web application. As we have Document Object Model (DOM) to have control over manipulating the data, similarly, we have Browser Object Model (BOM) that provides us to with the control on how applications are viewed on the browser. 

The navigator object is a window property that can be accessed by

window.navigator or navigator

Table 1: Properties of Navigator Object

Below are mentioned some navigator object properties

PropertyDescription
appCodeNameReturns the code name of the browser
appNameReturns the name of the browser
appVersionReturns the version information of the browser
cookieEnabledDetermines whether cookies are enabled in the browser
geolocationReturns a Geolocation object that can be used to locate the user’s position
languageReturns the language of the browser
onlineDetermines whether the browser is online
platformReturns for which platform the browser is compiled
productReturns the engine name of the browser
userAgentReturns the user-agent header sent by the browser to the server

Table 2: Methods of Navigator Object

MethodDescription
javaEnabled()Specifies whether or not the browser has Java enabled
taintEnabled()Removed in JavaScript version 1.2. Specifies whether the browser has data tainting enabled

Data tainting allows one window to see the properties in another window and is removed since it proved to be a high-security risk.

Example #1

Navigator Properties and Methods

Code:

<!doctype html>
<script>
document.write("<strong>Code Name of the Browser</strong> : ",navigator.appCodeName + "<br><br>");
document.write("<strong>Name of the Browser</strong> : ",navigator.appName + "<br><br>");
document.write("<strong>Cookies Enabled</strong> : ",navigator.cookieEnabled + "<br><br>");
document.write("<strong>Platform of the Browser</strong> : ",navigator.platform + "<br><br>");
document.write("<strong>Browser in onLine Mode</strong> : ",navigator.onLine + "<br><br>");
document.write("<strong>Java Enabled</strong> : ",navigator.javaEnabled());
</script>
</html>
OUTPUT:-Code Name of the Browser : Mozilla

Name of the Browser : Netscape

Cookies Enabled : true

Platform of the Browser : MacIntel

Browser in onLine Mode : true

Java Enabled : false

Table 3: Collections of Navigator Object

The table below lists the collections present in the JavaScript navigator object and then we will see one example of it.

CollectionDescription
plugins[]returns a reference to all the embedded objects in the document
mimeTypesreturns a collection of MIME types supported by the client browser

The mime property has three predefined fields:

  • name – the name of the MIME type (video/mpeg)
  • description – description of the type
  • suffixes – list of all possible file suffixes(extensions of file) for the MIME type.
Example #2

JavaScript Navigator Collection

Code:

<!doctype html>
<script>
var plugin = navigator.plugins["Flash Player"];
if (plugin)
document.write("Plugin Present")
else
document.write("You don't have Flash Player installed!")
</script>
</html>

Example# 3

JavaScript Navigator Property – geolocation

Code:

<!DOCTYPE html>
<html>
<body>
<script>
navigator.geolocation.getCurrentPosition(showPosition);
function showPosition(position) {
console.log("Latitude: " + position.coords.latitude + "\n" +"Longitude: " + position.coords.longitude);
}
</script>
</body>
</html>

Comments

Popular posts from this blog

Top 10 topics to make YouTube video in angular

  Here are ten topic suggestions for making YouTube videos on Angular: Getting Started with Angular: An Introduction to the Angular Framework Components in Angular: Understanding and Creating Angular Components Directives in Angular: Understanding and Using Angular Directives Angular Routing: Setting up Routes and Navigation in Angular Applications Forms in Angular: Creating and Validating Forms with Angular Reactive Forms Pipes in Angular: Understanding and Using Angular Pipes to Transform Data Services in Angular: Creating and Using Angular Services for Data Management Angular Animations: Adding Animations to Angular Applications Angular Material: Implementing Material Design in Angular Applications Advanced Angular Topics: Exploring Advanced Angular Topics like Lazy Loading, AOT Compilation, and Dynamic Components.

Top 5 javascript frameworks

  Here are the top 5 JavaScript frameworks : React: Developed and maintained by Facebook, React is a popular JavaScript library for building user interfaces. Angular: Developed and maintained by Google, Angular is a complete framework for building dynamic web applications. Vue.js: A relatively new JavaScript framework, Vue.js has gained a lot of popularity in recent years for its simplicity and performance. Ember.js: Ember.js is a JavaScript framework that emphasizes conventions over configuration, making it a good choice for complex web applications. Backbone.js: Backbone.js is a lightweight JavaScript framework that provides structure for web applications, particularly those that need to work with a lot of data. It's worth noting that the popularity of these frameworks can change over time, and different frameworks may be better suited for different types of projects and use cases.