Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use href,hostname,pathname in location

Shulou Source: shulou.com Published: 2022-06-01 03:29:45 10月31日 Update

This article mainly introduces the relevant knowledge of how to use href,hostname,pathname in location, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to use href,hostname,pathname in location. Let's take a look at it.

How to use href,hostname,pathname in location

The _ window.location object can be written without the window prefix.

_ window.location.href returns the href (URL) of the current page

_ window.location.hostname returns the domain name of the web host

_ window.location.pathname returns the path or file name of the current page

Example

Displays the href (URL) of the current page:

Document.getElementById ("demo"). InnerHTML = "Page location is" + _ window.location.href

Window Location Hostnam

The _ window.location.hostname property returns the name of the Internet host (of the current page).

Example

Displays the name of the host:

Document.getElementById ("demo"). InnerHTML = "Page hostname is" + _ window.location.hostname

The page hostname is www.w3school.com.cn

Window Location path name

The _ window.location.pathname property returns the pathname of the current page.

Example

Displays the pathname of the current URL:

Document.getElementById ("demo"). InnerHTML = "Page path is" + _ window.location.pathname

The page path is / js/js_window_location.asp

This is the end of the article on "how to use href,hostname,pathname in location". Thank you for reading! I believe everyone has a certain understanding of the knowledge of "how to use href,hostname,pathname in location". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Page host path instance knowledge path name content name attribute article but not value location usage prefix Internet domain name object simple operation file Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB OPPO Reno macOS Linux Apple