JavaScript Window.location Object __java

Source: Internet
Author: User
Tags browser cache
JavaScript window.location ObjectsExample Note method

Often use window.location, its structure is always unable to remember, simple comb, easy to query later. Sample

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

Property meaning value
Protocol Agreement "http:"
Hostname Name of the server "B.a.com"
Port Port "88"
Pathname Part of the host name in the URL "/index.php"
Search "?" The latter part, also known as 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 equivalent to each other and can be exchanged using

The 8 attributes of location are readable and writable, but only the writing of href and hash makes sense. For example, changing the location.href will reposition to a URL, and the modification Location.hash will jump to the tag (<a id= "name" > or <div id= "id" >, etc.) in the current page (if any ), 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 "?" After
Hash "#when =2011#first" The content after the first "#"
MethodLocation.assign (URL) location.assign (' http://www.baidu.com '); equal to Window.location = ' http://www.baidu.com '
This way the new address is put into the browser history stack, meaning that the back button can still return to the page after the new page has been transferred. The Location.replace (URL) is the same as the Assign method, but deletes this page from the browser history stack, which means that the back button cannot return to the page when you jump 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. Overload from the server side when force is true, and false is overloaded from the browser cache, and the default value is False.

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.