Do you really know window. location?

Source: Internet
Author: User

If you know a little about JS Code, you will generally knowwindow.location.hrefThis attribute. Use this property to obtain the URL of the page:

window.location.href = window.location.href;

Okay, I tell you, it's so weak. In fact, native JavaScript really has everything.

Properties of the window. location object
Attribute Description
Hash URL (Anchor) starting from)
Host Host name and port number of the current URL
Hostname Host Name of the current URL
Href Complete URL
Pathname Path section of the current URL
Port Port Number of the current URL
Protocol Protocol of the current URL
Search From Question mark (?) Start URL (query part)

Take the mango small station as an example.window.location.hrefObtain a page parameter and obtain the following results:

Window. location. hash

You can use JS to locate the anchor.window.hashComplete with the element ID. For example, to quickly locate a comment on the page, you can directly use the following code:

window.location.hash = "#comment-5981";

In addition, Twitter, Facebook, and Google have been widely used.#!This form of hash method processes the URL backtracking function of Asynchronous Interactive pages.

Window. location. search

If there is such a URL:

http://www.google.com.hk/search?hl=zh-CN&source=hp&biw=1400&bih=935&q=%E8%8A%92%E6%9E%9C%E5%B0%8F%E7%AB%99&aq=f&aqi=&aql=&oq=

How can I capture parameters requested by PAGE GET using JS scripts? In fact, use it directlywindow.location.searchAnd then use the split method to traverse the free organization data format in a loop.

In addition, if you refresh the page based on your search criteria, you only need to setwindow.location.searchYou can.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.