Home > Article > Web Front-end > JavaScript Strengthening Tutorial—Window Location
Window Location
window.location object can be written without using the window prefix.
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 used Protocol (http:// or https://)
Window Location Href
location.href property returns the URL of the current page.
Example
Return the entire URL (of the current page): <script> document.write(location.href); </script>The output of the above code is: http://www.w3school.com.cn/js / ... indow Location Pathname
location.pathname property returns the path name of the URL.
Example
Return the path name of the current URL: <script> document.write(location.pathname); </script>The output of the above code is: /js/js_window_location.aspWindow Location Assign
location.assign() Method loads a new document.
Example
Load a new document: