Home > Web Front-end > JS Tutorial > JavaScript Strengthening Tutorial—Window Location

JavaScript Strengthening Tutorial—Window Location

巴扎黑
Release: 2016-11-25 14:13:53
Original
1136 people have browsed it

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: <script> function newDoc() { window.location.assign("http://www.w3school.com.cn";) } </script>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template