Location is one of the BOM objects that provides information about the documents loaded in the current window, as well as some navigational features. In fact, the location object is the property of the Window object and the property of the Document object: So window.location and document.location are equivalent.
Given the relatively small number of properties for this object, here are a few more:
First look at the properties of the Location object
There are only three methods for location objects, as shown in the following figure
A simple example of a jump page
<span style= "FONT-SIZE:18PX;" >location.href= ' http://www.baidu.com ';
Alert (LOCATION.HREF);</span>
In web development, we often need to get things like. Id&search=ok This type of URL's key-value pairs, then through the location object, we can write a function to get one by one.
<span style= "FONT-SIZE:18PX;" >function Getargs () {
//Create an array of key-value pairs
var args=[];
Remove. Number
var qs=location.search.length>0?location.search.substring (1): ';
Split fractional Group
var items=qs.split (' & ') by & string;
var item =null,name=null,value=null;
Traversal for
(var i=0;i<items;i++) {
item=items[i].split (' = ');
NAME=ITEM[0];
VALUE=ITEM[1];
Store the key value pairs in an array to
Args[name]=value;
return args;
}
var args=getargs ();//Call Function
alert (args[' id '));
Alert (args[' search ']);</span>
About the Location object method is no longer detailed, basically jump to the specified URL, here is a point, that is the reload () method, look at the following code
<span style= "FONT-SIZE:18PX;" >location.reload ();
Location.reload (True);</span>
The difference between the two is that a Boolean parameter is passed in the method, which is the most efficient way to reload, but the page may be taken out of the cache, and the latter is forced to load or reload the page from the server source only.
At this point, the introduction of the Location object is over, location object is to manipulate the page's jump, as well as the content of the URL to do related operations and settings.