Location objects
The Location object contains information about the current URL, a part of the Window object that can be accessed through the Window.location property
Location Object Properties
The href property is a readable, writable string that sets or returns the full URL of the currently displayed document, so we can read and display the contents of the new URL by setting a new URL for the property
Syntax: Location.href = URL;
Example: location.href = ' http://www.111cn.net ';
A hash is a readable, writable string that is the anchor part of a URL (the part that begins with the # number).
Grammar: Location.hash = anchorname;
Example: Location.hash = ' myanchor '; <a name= "Myanchor" > Jump to Here </a>//page jump
You can use this property and anchor points to implement jumps within the page
Host returns the name and port number of the current URL
Grammar: Location.host;
Example: document.write (Location.host); URL address is: http://192.168.1.101/test/test.php output 192.168.1.101
Hostname returns the host name of the current URL
Grammar: Location.hostname;
Example: document.write (Location.hostname); URL address is: http://192.168.1.101/test/test.php output 192.168.1.101
Pathname is a readable, writable string that sets or returns the path portion of the current URL
Syntax: location.pathname = path;
Example: document.write (Location.pathname); URL address is: http://192.168.1.101/test/test.php output/test/test.php
Location.pathname = ' test/test3.php '; Jump to test3.php page
Port is a readable and writable string that can set or return the ports portion of the current URL
Grammar: Location.port = portnumber;
This did not do experiments, you can experiment, talk about how it!
Protocol is a readable and writable string that sets or returns the protocol for the current URL
Syntax: location.protocol = path;
Example: document.write (Location.protocol); The URL address is: http://192.168.1.101/test/test.php output http:
Search is a readable and writable string that sets or returns the query portion of the current URL (question mark?). After the section)
Grammar: Location.search = Path_from_questionmark;
Example: document.write (Location.search); The URL address is: http://192.168.1.101/test/test.php?key=test output? key=test
Location.search = ' key=test '; Look at the URL address has become: http://192.168.1.101/test/test.php?key=test
Location Object method
Assign () loads a new document
Syntax: Location.assign (URL);
Example: Location.assign (' http://www.111cn.net ');
Reload () is used to reload the current document
Syntax: Location.reload ();
Replace () replaces the current document with a new document, and the Replace () method does not generate a new record in the History object, and when this method is used, the new URL overwrites the current record in the History object
Grammar: Location.replace (Newurl);
Example: Location.replace (' http://www.111cn.net ');