adplus-dvertising
 
PROGRAMMING

JavaScript Window Location Object Tutorial.

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 item and how might you use it in various ways.

What is the use of window.location


First we can involve it for getting the worth of current site page address or URL
Second For diverting the current page to new page.


A few Types Of Window Location

There are 5 fundamental sorts o window.location. Every one of the 5 kinds will accomplish distinctive 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 current website page address or URL and it can divert the current page too.

Get The Current Page URL

var OP = window.location.href;

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

Redirect The Current Page

For Redirect the current page URL we will physically set the worth of window.location.href.

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

In the event that Your present page url is http://something.com then 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 records are facilitated.

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

Code

var operation = window.location.hostname;

This javascript code will return the current 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, at that point, content will set www.anything.com as the worth of variable operation

Window Location Pathname (window.location.pathname)

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

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

Window Location Protocol (window.location.protocol)


The window.location.protocol gives us the web convention of the current URL

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

var operation = window.location.protocol;

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

Window Location Assign (window.location.assign)


The window.location.assign() basically load another archive or new URL.

Ex –

window.location.assign(‘https://www.veganab.co’);

This code will stack http://www.veganab.co .

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button
JOIN TO WATCH IPL MATCHES👈

Adblock Detected

It Seems that you are using some ad blocking software/VPN/ Proxy/Server/Incognito mode Which is preventing the page from fully loading.