A simple understanding of location objects:
1. The location object covers the current page (this page) or, more directly, the URL information of the currently loaded html document
2. The location object is a property of the window object and can be accessed through window.location
Here is some URL (resource locator) related information:
In a browser, URLs are usually composed of the following parts:
[Protocol][host][path][query]
Agreement: Common protocols are:
http:// means that the resource file is on the web server
ftp:// means that the resource file is in the ftp server on the network
host: host name and port number, for example, the commonly used host for native tomcat: localhost:8080
path: The path information of the project is generally composed of "/" and characters, and "/" is a superior-level relationship.
query: Generally, it starts with "?", and adds some song key value pairs (key=value) afterwards. Multiple key value pairs are separated by "&". They can be used for dynamic web pages, pass parameters to the server side, use for background operations, query database conditions, etc., submit table data, etc., and can all be placed here for submission. Things involving security need to be encrypted separately or through other methods. . . .
You can also add parameters starting with the "#" sign at the end of the query, but this thing is not used at present, so I won't make any comments for the time being.
Location object properties:
1.href attribute: the complete URL information of the current page, including protocol, host name, port number, query parameters, # information, etc., all of which are included.
2.host attribute: host name and port number, such as localhost:8080 local
3.hostname: hostname
4.port: port number in url
5.pathname: The part of the path content in the url contains "/"
6.protocol: protocol
7.serach: The query part starting with "?"
8.hash: content starting with "#"
Common usage of location
Obviously, in addition to providing developers with convenient attribute information, there is another more important and commonly used purpose.
Reload the page, which can be used to refresh the document content, but the more important purpose is to reload the document content after modifying the href information.
location.href: After assignment, the browser will refresh the content of the document based on this specified brand new url.
location.reload(): reload the document
Assist us in solving cross-domain issues of pages:
1. Refresh the current page
window.location.href =url//I am used to using this method
self.location.href =url
location.href =url
All three methods above can be used to refresh the current page (reload according to the specified url, which can be another brand new document, replacing the current document)
2. When using an iframe in the parent page to include the child page
The parent page refreshes the child page:
window.frames["id"].location.reload()//id is the id of the iframe in the page
3. The child page refreshes the parent page
partition.location.reload()
self.opener.location.reload()
There are many methods, and we will continue to summarize them as we use them in the future! ! ! !
Other common methods:
location.replace() //Replace the current document with a new document
location.assign() //Load new document