Window Location
The window.location object provides information about the current URL or the URL of the current web page. It allows you to read and modify various properties related to the browser's location.
Here are some commonly used properties of the window.location object:
location.href
Returns the complete URL of the current page.
location.protocol
Returns the protocol of the current URL, such as "http:" or "https:".
location.host
Returns the hostname and port number of the current URL.
location.hostname
Returns the hostname (domain) of the current URL.
location.port
Returns the port number of the current URL, if specified.
location.pathname
Returns the path and filename of the current URL.
location.search
Returns the query string part of the current URL.
location.hash
Returns the fragment identifier (anchor) part of the current URL.
By accessing these properties, you can obtain various details about the current URL, such as its protocol, hostname, path, query parameters, and fragment identifier. This information can be used to perform URL manipulations, retrieve specific parts of the URL, or navigate to different pages programmatically.
assign()
The assign() method of window.location is used to load a new document. It navigates the browser to the specified URL.
reload()
The reload() method of window.location is used to reload the current web page. It reloads the page with the same URL.
replace()
The replace() method of window.location is used to replace the current document with a new one. It navigates the browser to the specified URL, but it does not store the current page in the session history.
location.origin
The origin property of window.location represents the protocol, hostname, and port number of the current URL. It provides the base URL of the current page.