Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use href,hostname,pathname in location

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report