JavaScript window.location Objects

Source: Internet
Author: User
Tags browser cache

    • Example
    • Attention
    • Method

Often use window.location, its structure always can't remember, simple comb under, convenient later query.

Example

Url:http://b.a.com:88/index.php?name=kang&when=2011#first

Properties meaning value
Protocol Agreement "http:"
Hostname The name of the server "B.a.com"
Port Port "88"
Pathname The part of the URL that is behind the host name "/index.php"
Search "?" The later part, also called the query string "? name=kang&when=2011"
Hash Returns the content after "#" "#first"
Host equals hostname + Port "B.a.com:88"
Href: The full URL of the current page "Http://www.a.com:88/index.php?name=kang&when=2011#first"

Window.location and document.location are mutually equivalent and can be exchanged for use

The 8 properties of the location are both readable and writable, but only the href and hash write make sense. For example, changing the location.href will relocate to a URL, while modifying Location.hash will jump to the anchor (<a id= "name" > or <div id= "id" > etc.) name tag (if any) in the current page ), and the page will not be reloaded

Attention

url:http://b.a.com:88/index.php?name=kang&how= #when =2011#first

Search "? name=kang&how=" The first one "?" After
Hash "#when =2011#first" The content after the first "#"
Method
Location.assign (URL)
Location.assign (' http://www.baidu.com '); Equivalent to window.location = ' http://www.baidu.com '
This way the new address is placed in the browser history stack, which means that the back button can still go back to the page after going to the new page.
Location.replace (URL)
As with the Assign method, this page is removed from the browser history stack, meaning that the back button cannot return to the page after jumping to a new page. At present, IE, chrome is just a simple jump, only Firefox will delete the history of this page.
Location.reload (Force)
reload the current page. The force is true when overloaded from the server side; False is overloaded from the browser cache, and the default value is False.

JavaScript window.location Objects

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.