Location object properties in HTML documents are understood and commonly used
- 2020-03-30 03:40:15
- OfStack
Simple understanding of location objects:
1. The location object contains the url information of the current page (this page) or, more directly, the currently loaded HTML document
2. As a property of the window object, the location object can be accessed through window.location
By the way, here is some information about urls (resource locators) :
In a browser, a URL usually consists of the following parts:
[agreement] [host] [path] [query]
Protocols: common protocols are:
http:// indicates that the resource file is on the web server
ftp:// indicates that the resource file is on the FTP server on the network
Host: hostname and port number, such as host: localhost:8080, commonly used by native tomcat
Path: the path information of a project is usually composed of "/" and characters. "/" is the relationship between superior and subordinate
Query: it usually starts with "?" Song beginning, followed by some key/value pair (key = value) of the situation, multiple key value pairs separated by "&", can be used for dynamic web pages, the parameter to the server side, used for the background about the operation, database query conditions, etc., submit the form data, etc., can be submitted here, involving the safety of things need to get another encryption or by other means...
Query can also be followed by an argument that starts with a "#" sign, but that's not the case at the moment and I'm not going to say anything
Location object property:
1. Href attribute: the complete url information of the current page, including the protocol, hostname, port number, query parameter, # information, etc., is included
2. Host property: host name and port number, such as localhost:8080 native
3. Hostname: hostname
4. Port: the port number in the url
5. Pathname: the part of the path in the url that contains the "/" part
6. Protocol: agreement
7. Serach: "& # 63;" The query section begins
8. Hash: something that starts with a "#"
Common usage of location
Obviously, there is a more important and common use than simply providing developers with easy access to property information
Reloading the page can be used to refresh the document content, but a more important use is to reload the document content after modifying the href information
Location.href: after the assignment, the browser will refresh the document based on the new url specified
Location.reload () : reload the document
Help us solve cross-domain problems:
1. Refresh the current page
Window.location.href =url// I'm used to this method
The self. The location. Href = url
The location. The href = url
All three of the above methods can be used to refresh the current page (reload it according to the specified url, which can be another completely new document to replace the current document)
2. When a parent page contains a child page using an iframe
Parent page refreshes child page:
Window.frames ["id"].location.reload()//id is the id of the iframe on the page
3. Child page refreshes parent page
Parant. Location. Reload ()
Self. Opener. Location. Reload ()
Methods have a lot of, with the actual use of the future continue to summarize!!
Other common methods:
Location.replace () // replace the current document with a new document
Location.assign () // load the new document