The location property of a window (i.e. window.location) is a reference to a Location object.
window.location object represents the current URL of the document being displayed in a window.
window.location object can be written without the window prefix.
The following section will show you how to get the URL of page as well as hostname, protocol, etc. using the location object property.
location.href property returns the URL of the current page.
var x = location.href;
location.hostname property returns the name of the internet host (of the current page).
var x = location.hostname;
location.pathname property returns the pathname of the current page.
A pathname is a string that starts after hostname containing an initial '/' followed by the path of the URL.
var x = location.pathname;
location.protocol property returns the web protocol of the current URL, including the colon (:).
var x = location.protocol;
location.port property returns the number of the internet host port (of the current page).
var x = location.port;
Note: The port property returns an empty string if the port number is not specified in the URL or if it is the scheme's default port (80 for http and 443 for https).
location.assign() method causes the window to load and display the document at the URL specified.
The reference section contains descriptions and examples of all location properties and methods.