Location object attribute in HTML document and common usage _ basics

Source: Internet
Author: User

A simple understanding of the Location object:

The 1.location object covers the current page (this page) or, more directly, the URL information for this HTML document that is currently loaded

The 2.location object is a property of the Window object that can be accessed through window.location old

Here are some information about URLs (Resource Locator):

URLs typically consist of the following sections in a browser:

Agreement [Host] [Path] [Query]

Protocol: Common protocols are:

http://indicates that the resource file is on the Web server

FTP://indicates that the resource file is in the FTP server on the network

Host: hostname and port number, such as native tomcat commonly used host:localhost:8080

Path: project information, usually by "/" and characters, "/" for the subordinate relationship

Query: usually with "? "At the beginning, add some song key value pairs (key=value) of the situation, a number of key value pairs are separated by" & ", can be used for dynamic Web pages, pass parameters to the server side, for the background of the operation, query database conditions, etc., submit form data, etc., can be placed here to submit, Things that involve security need to be encrypted differently or otherwise ....

You can also add an argument that starts with "#" at the back of query, but it's not available at the moment.

Location Object properties:

1.href properties: Full URL information for the current page, including protocol, hostname, port number, query parameters, #信息等等等, complete with

2.host Properties: Host name and port number, such as localhost:8080 native

3.hostname: Host Name

Port number in 4.port:url

The path content in the 5.pathname:url contains part of the "/" content

6.protocol: protocol

7.serach: to "?" Start the query section content

8.hash: Content starting with "#"

Common usage of location

Obviously, there is a more important and commonly used use in addition to providing convenient attribute information to developers

Reloading the page can be used to refresh the contents of the document, but the more important purpose is to reload the document content after modifying the href information

Location.href: After assigning the value, the browser refreshes the contents of the document based on this new URL that you specify.

Location.reload (): Reloading document

Help us solve the problem of page cross domain:

1. Refresh the current page

Window.location.href =url//I used to use this method

Self.location.href =url

Location.href =url

All three of these methods can be used to refresh the current page (reload according to the specified URL, can be another new document, replace the current document)

2. When using an IFRAME in a parent page to include a child page

Parent page Refresh Child page:

window.frames["id"].location.reload ()//ID is the ID of the IFRAME in the page

3. Child page Refresh parent page

Parant.location.reload ()

Self.opener.location.reload ()

There are a lot of methods that continue to be summed up with actual use later!!!!

Other common methods:

Location.replace ()//replace the current document with a new document

Location.assign ()//Load New document

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.