JavaScript Getting Started Tutorial (8) Location Address Object _ Basics

Source: Internet
Author: User
To represent the address of a window, use the < Window object >.location. Previously wrote a piece with window.location.href implementation to refresh another frame page, hereby I looked at the detailed usage of Locaiton, which is somewhat improved, as follows:
Note: The two addresses belonging to different protocols or different hosts cannot refer to each other's location objects, for security reasons. For example, the current window opens a page under "www.a.com," and another window (the object named: Bwindow) opens with a "www.b.com" page. If you use "bwindow.location" in the current window, you will get an error: "No permissions." This error cannot be received with the error handler (event Handler, see OnError events).
First, briefly describe the location properties, usage, and related examples:
Location
Contains information about the current URL. The Location object describes the complete URL associated with a given Window object. Each property of the location object describes the different attributes of the URL.
Typically, a URL will have the following format: Protocol//HOST: Port/path name # Hash ID? search criteria
For example: http://www.webjx.com/jiaocheng/index.html#topic1?x=7&y=2 These parts meet the following requirements:
"Protocol" is the starting part of the URL until it is included in the first colon.
"Host" describes the host and domain name, or the IP address of a network host.
"Port" describes the communication port that the server uses for communication.
The path name describes the path-side information of the URL.
The hash ID describes the anchor name in the URL, including the Hash Mask (#). This property applies only to HTTP URLs.
Search criteria describes any query information in the URL, including a question mark. This property applies only to HTTP URLs. The search criteria string contains a pairing of variables and values, and a "&" connection between each pair.
Properties Overview
Protocol the Protocol that returns the address, value is ' http: ', ' https: ', ' File: ' And so on.
Hostname return address host name, for example, a "http://www.microsoft.com/china/" address, Location.hostname = = ' www.microsoft.com '.
Port returns the port number of the address, and the general HTTP port number is ' 80 '.
Host returns the hostname and port number, such as: ' www.a.com:8080 '.
Pathname returns the path name, such as "http://www.a.com/b/c.html", location.pathname = = ' b/c.html '.
Hash returns "#" and later content, such as "http://www.a.com/b/c.html#chapter4", Location.hash = = ' #chapter4 '; if there is no "#" in the address, an empty string is returned.
Search return "?" and later content, such as "http://www.a.com/b/c.asp?selection=3&jumpto=4", location.search = = '? selection=3&jumpto= 4 '; If there is no "?" in the address, an empty string is returned.
HREF returns all of the above, that is, return the entire address. How to show it on the browser's address bar is how to return it. If you want a window object to open an address, you can use "Location.href = ' ... '", or you can use "location = ' ... '" to do this.
Overview of methods
Reload () is equivalent to pressing the "refresh" (IE) or "Reload" (Netscape) key on the browser.
Replace () opens a URL and replaces the address of the current location in the History object. When you open a URL with this method, pressing the "Back" button on the browser will not return to the page you just made.
Second, the location page jump JS as follows:
Copy Code code as follows:

Simple jump
function GotoPage (URL) {
eg. var url = "newsview.html?catalogid=" +catalogid+ "&pageid=" +pageid;
window.location = URL;
}
An upgrade to the location usage, passing parameters for a single page
function Goto_catalog (ICAT) {
if (icat<=0) {
Top.location = ".. /index.aspx "; Top out
} else {
Window.location = ".. /newscat.aspx?catid= "+ICAT;
}
}
Jump page for specified frame, two methods available
function Goto_iframe (URL) {
Parent.mainFrame.location = ".. /index.aspx "; //
Parent.document.getElementById ("MainFrame"). src = ".. /index.aspx ";/use DOM to change page//At the same time I added Dom's notation
}
Jumps the page for the specified frame because the parent.iframename.location= "... /index.aspx "; Methods can not be implemented, mainly "Parent.iframename" in the Iframename in JS is the default node, and can not transfer the parameters passed over, so with the DOM to achieve the pass two parameters of the frame jump page, I hope that the man is not hesitate to enlighten!
function Goto_iframe (iframename,url) {
Parent.document.getElementById (iframename). src = ".. /index.aspx ";/use DOM to change page by Iframename
//}
Back to Home

function GoHome () {
Top.location = "/index.aspx";
}

Related Article

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.