May 06, 2021 JavaScript
The window.location object is used to get the address (URL) of the current page and redirect the browser to the new page.
This method can be used between labels with onclick events or jumps that meet certain conditions, characterized by convenience and flexibility.
Window.location objects are written without the prefix window. Some examples:
Some examples:
location.hostname returns the domain name of the web host
location.pathname returns the path and file name of the current page
location.port returns the port of the web host (80 or 443)
location.protocol returns the web protocol used (http:// or https://)
The location.href property returns the URL of the current page.
Returns the entire URL (of the current page):
The above code output is:
The location.pathname property returns the path name of the URL.
Returns the path name of the current URL:
The above code output is:
The location.assign() method loads a new document.
Load a new document:
JavaScript Encyclodedd: JavaScript Redirect Jump