The location object of JavaScript learning 5:bom __java

Source: Internet
Author: User

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.

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.