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

How to get the CPU temperature using ADB?

import os # Function to get the CPU temperature using ADB def get_cpu_temperature():     try:         # Run the ADB command and redirect the output to a temporary file         os.system("adb shell cat /sys/class/thermal/thermal_zone0/temp > temp.txt")         # Read the temperature from the temporary file and convert to Celsius         with open("temp.txt", "r") as file:             temperature = int(file.read().strip()) / 1000.0             return temperature     except Exception as e:         print("Error:", e)         return None     finally:         # Remove the temporary file         os.remove("temp.txt") # Function to check temperature and trigger alarm if necessary def check_temperature_and_notify(threshold):     temperat...

How to call API in angular & with an example of PHP API

How to call API in angular & with an example of PHP API . Software required:- Node ->  https://nodejs.org/en/download/ VS Code ->  https://code.visualstudio.com/download Angular CLI -> npm install - g @angular / cli To understand how to call API in angular follow the below steps:- Step:1 Project Setup 1. Create a project in angular ->  ng new project name 2. Install npm -> npm i 3. Import HttpClientModule in app.module.ts -> import { HttpClientModule } from '@angular/common/http' ; 4. Add provider providers : [ WebserviceService ], example -> ng new crudInAngularPHP Step:2 API Service 1. Create a service with name webservice -> ng g s services/webservice 2. import modules import { HttpClient, HttpHeaders, HttpRequest, HttpEvent } from '@angular/common/http'; 3 .    C all constructor  constructor( private http: HttpClient) 4. Add a common function to get a response of API with name postRequest:-      ...

What is JavaScript? Why JavaScript? How to use javascript?

 WWH JavaScript Watch here with full example and with github:  Watch Now 1. Question. What is JavaScript? Answer :- Javascript is a scripting language. And it's basically used to make web pages more user-friendly and more interactive.     Few Important points related to javascript:- JavaScript is an untyped language.(What does it mean?) Unlike c/java or other programming languages, you don't need to define/declare type of variables JavaScript is an interpreted language.(Means?) Programs written in c/c+ or java, you need to compile first and after that, u can get output. but codes/programs written in javascript will give you output without compilation process. 2. Question. Why JavaScript?  Answer:- Javascript is basically used to make web pages more authentic. For example, you have a signup form of a user and there is a Pincode input box and you want to get the city on the input of pin code so you can add this functionality into your web page with the help of jav...