JavaScript window. location object, javascriptwindow

Source: Internet
Author: User

JavaScript window. location object, javascriptwindow

Window. location is often used, and its structure is hard to remember. It can be easily sorted to facilitate future queries.

Example
URL: http:// B .a.com: 88/index. php? Name = kang & when = 2011 # first

Attribute Description Value
Protocol: Protocol "Http :"
Hostname: Server Name "B .a.com"
Port: Port "88"
Pathname: The part after the host name in the URL "/Index. php"
Search: "? ", Also known as the query string "? Name = kang & when = 2011"
Hash: Returned content after "#" "# First"
Host: Equal to hostname + port "B .a.com: 88"
Href: Complete 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 used in exchange.

The eight attributes of location can be read and written, but only href and hash write make sense. For example, change location. href locates a URL and modifies the location. hash will jump to the anchor (<a id = "name"> or <div id = "id">) name tag on the current page (if any ), and the page will not be reloaded.

Note:
URL: http:// B .a.com: 88/index. php? Name = kang & how = # when = 2011 # first

Search: "? Name = kang & how =" First "? After
Hash: "# When = 2011 # first" Content after the first "#"
Search :"? Name = kang & how = "first "? After
Hash: "# when = 2011 # first" content after "#"

Method

Location. assign (url)
Location. assign ('HTTP: // www.baidu.com '); equivalent to window. location = 'HTTP: // www.baidu.com'
In this way, the new address will be stored in the browser history stack, which means that after the new page is transferred, the "back" button can still return to the page.
Location. replace (url)
The method is the same as the assign method, but the page is deleted from the browser history stack. That is to say, the page cannot be returned after the "back" button is redirected to the new page. Currently, IE and Chrome are simple jumps. Only Firefox deletes the history of this page.
Location. reload (force)
Reload the current page. If force is set to true, It is reloaded from the server. If false, it is reloaded from the browser cache. 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.