javascriptJavaScript Window Location Object FullGuide

javascriptJavaScript Window Location Object Full Guide

JavaScript Window Location Object Full Guide

You will discover that how you can utilize window area object of JavaScript. In this post you will get the all data about window area article and how might you use it in various ways.

What is the utilization of window.location
First we can utilize it for getting the worth of current website page address or URL
Second For diverting the ongoing page to new page.

A few Types Of Window area

There are 5 essential sorts o window.location. Every one of the 5 sorts will accomplish different work.

window.location.href
window.location.hostname
window.location.pathname
window.location.assign()
window.loacation.protocol

Window Location Href ( window.location.href )

The window.location.href gives us the ongoing page address or URL and it can divert the ongoing page too.

Get The Current Page URL

var OP = window.location.href;

on the off chance that your ongoing page url is – https://something.com/test
then the window.location.href will set “https://something.com/test” the worth of variable OP

Divert The Current Page

For diverting the ongoing page URL we will physically set the worth of window.location.href.

window.location.href = ‘https://google.com‘;

On the off chance that Your ongoing page url is http://something.com the above JavaScript code will divert the page to https://google.com

Window Location Hostname ( window.location.hostname )
window.location.hostname provides us with the name of space of current page or Hostname.
Hostname implies where the documents are facilitated.

in the event that you open a URL ex-google.com/login the hostname for this page is google.com

Code –

var operation = window.location.hostname;

This javascript code will return the ongoing page hostname as a worth of variable operation
On the off chance that this code is written in this page – www.anything.com/blog/test.html
then, atthatpoint, contentwill set www.anything.com astheworth ofvariable operation

Window Location Pathname (window.location.pathname)

window.location.pathname gives us the way address of the ongoing page.

On the off chance that You are in this page ex – www.itscybertech.com/p/about.html
then, at that point, the way name for the above url is/p/about.html

var operation = window.location.pathname;

the above JavaScript code will set the ongoing page pathname as the worth of variable operation

Window Location Protocol (window.location.protocol)
The window.location.protocol gives us the web convention of the ongoing URL

assuming you are visiting a site ex-https://facebook.com
then the webprotocol for the above URL is https:

var operation = window.location.protocol;

the above JavaScript code will return the webprotocol of the ongoing page.

Window Location Assign (window.location.assign)
The window.location.assign() just burden another record or new URL.

Ex –

window.location.assign(‘https://wplink.in‘);

This code will stack http://wplink.in .

Leave a Reply

Your email address will not be published.