The window.location object can be used to get the current webpage (URL) and to redirect the browser to a new webpage. The window prefix is not necessary but some cases we need it…
Some of the most important daily useful functions and methods of javascript window location are the window.location.href, the window.location.hostname, the window.location.pathname, window location.protocol, window.location.assign() etc
The window.location.href method return the current webpage URL.
var exp = window.location.href;
document.write("Current url of browser = "+exp);
The window.location.hostname method used to which is return the name of the current pages internet host.
var exp = window.location.hostname;
document.write("hostname = "+exp);
The window.location.pathname method is used for get the pathname of the current webpage.
var exp = window.location.pathname;
document.write("Pathname = "+exp);
The window.location.protocol method is used for get the protocol of the current webpage.
var exp = window.location.protocol;
document.write("Protocol = "+exp);
The window.location.assign() method loads a new document.
function newDocument() {
window.location.assign("https://www.tutsmake.com/")
}
☞ JavaScript Programming Tutorial Full Course for Beginners
☞ Learn JavaScript - Become a Zero to Hero
☞ Javascript Project Tutorial: Budget App
☞ E-Commerce JavaScript Tutorial - Shopping Cart from Scratch