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:
Returns the complete URL of the current page.
Returns the protocol of the current URL, such as "http:" or "https:".
Returns the hostname and port number of the current URL.
Returns the hostname (domain) of the current URL.
Returns the port number of the current URL, if specified.
Returns the path and filename of the current URL.
Returns the query string part of the current URL.
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.
The assign() method of window.location is used to load a new document. It navigates the browser to the specified URL.
The reload() method of window.location is used to reload the current web page. It reloads the page with the same URL.
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.
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.