Window. Location and document. Location Parsing

Source: Internet
Author: User
Tags close close time in milliseconds

Document. Location this object contains information about the current URL
Location. Host get port number
Location. hostname set or get Host Name
Location. href set or get the whole URL
Location. Port: set or obtain the port number of the URL.
Location. Search sets or retrieves the Section following the question mark in the href attribute

 

Application of window. Location
URL: Uniform Resource Locator (Uniform Resource Locator, URL)

The complete URL consists of the following parts: Scheme: // host: Port/path? Query # fragment;
Scheme: Communication Protocol
Common HTTP, FTP, Maito, etc.

HOST: Host
The host name or IP address of the server (Computer) Domain Name System (DNS.

Port: Port Number
INTEGER (optional) Default port used when the scheme is omitted. For example, the default port of HTTP is 80.

Path: Path
A string separated by zero or multiple "/" symbols. It is generally used to represent a directory or file address on the host.

Query: Query
Optional. Used for dynamic web pages (such as CGI, ISAPI, PHP/JSP/asp. net and other technologies to produce web pages) transmission parameters, can have multiple parameters, separated by the "&" symbol, each parameter name and value are separated by the "=" symbol.

Fragment: Information Fragment
String used to specify fragments in network resources. For example, if a webpage contains multiple glossary, you can use fragment to directly locate the glossary. (Also called anchor .)

 

For such a URL
Http://www.x2y2.com: 80/Fisker/post/0703/rows configurlocation.html? Ver = 1.0 & id = 6 # imhere

We can use JavaScript to obtain all the parts.
1, window. Location. href
The whole URL string (the complete address bar in the browser)
Returned value in this example: http://www.x2y2.com: 80/Fisker/post/0703/optional parameter location.html? Ver = 1.0 & id = 6 # imhere

2, window. Location. Protocol
URL protocol section
Returned value in this example: http:

3, window. Location. Host
Host part of the URL
Return Value in this example: www.x2y2.com

4, window. Location. Port
URL Port
If the default port 80 is used (Update: Even if port 80 is added), the return value is not the default port 80, but an empty character.
Returned value in this example :""

5, window. Location. pathname
URL path (that is, the file address)
Returned value in this example:/Fisker/post/0703/window.location.html

6. Window. Location. Search
Query (parameter)
In addition to assigning values to dynamic languages, we can also assign values to static pages and use JavaScript to obtain expected parameter values.
Return Value in this example :? Ver = 1.0 & id = 6

7. Window. Location. Hash
Anchor =================================================== ===

 

[Document Object]
This object is an attribute of the window and frames objects. It is a document displayed in a window or frame.
Attribute
Alinkcolor activity link color (alink)
Anchor is an htmi anchor. It is created with the <a name => MARK (this attribute is also an object)
Anchors array lists the array of document anchors (<a name =>) (This attribute is also an object)
Bgcolor (bgcolor)
Cookie is a piece of information stored in the cookie.txt file. It is an attribute of the Document Object.
Text color of the fgcolor document (text features in the <body> MARK)
Form (<form>) (This attribute is also an object)
Forms Anay lists an array of form objects in the order they appear in the document (this attribute is also an object)
Lastmodified document last modification date
The link color of the linkcolor document, that is, the link feature in the <body> MARK (link to the document not observed by the user)
A <a href => mark in the Link document (this attribute is also an object)
An array of link objects in the links array document, arranged in the order they appear in the document (this attribute is also an object)
Location: the URL of the currently displayed document. You cannot change document. Location (because this is the location of the currently displayed document ). However, you can change window. Location (Replace the current document with other documents). Window. Location is also an object, and
Document. location is not an object
The URL of the document whose referrer contains the link. You can click this link to reach the current document.
Title document title (title>)
Vlinkcolor points to the link text color of the document you have observed, that is, the <body> marked vlink feature
Method
Clear the content of a specified document
Close close Document Stream
Open Document Stream
Write writes text to the document
Writeln writes text to the document and ends with a linefeed.

[Window object]
It is a top-level object, rather than the properties of another object, that is, the browser window.
Attribute
Defaultstatus default status message
The document currently displayed in the document (this attribute is also an object)
A frame (frame>) in the frame window (this attribute is also an object)
Frames array lists the array of Frame Objects in the window in the order they appear in the document (this attribute is also
Object)
History List of the history window (this attribute is also an object)
Number of frames in the length window
The complete (absolute) URL of the document displayed in the location window (this attribute itself is also an object ).
Obfuscation. The latter is the URL of the currently displayed document. You can change window. Location (Replace the current document with another document), but it cannot.
Document. Location (because this is the location of the currently displayed document)
When the name window is opened, the name of the window is assigned.
Opener indicates the window in which the script of the current window is opened using window. Open (this is cited by Netscape Navigator 3.0 Beta 3 ).
A new attribute)
Parent contains the synonym of the current frame window. An attribute of the frame and window objects.
Synonym for self current window or frame
Messages in status bar
Top: Synonym that contains the top-level browser window of the current framework
The synonym for the current window or frame of window, which is the same as self.
Method
Alert () open an alert message box
Cleartimeout () is used to terminate the work of the setTimeout method.
Close () Close the window
Confirm () opens a confirm message box. You can select OK or cancel. If you click OK, this method returns true and click
Cancel returns false
Blur () removes focus from the specified window (this is a new method introduced by Netscape Navigator 3.0 Beta 3)
Focus () brings the specified window to the foreground (another new method)
Open () open a new window
Prompt () opens a prompt dialog box. You can type a text in the box and return the entered text to the script.
SetTimeout () waits for a specified period of time in milliseconds, and then runs the command event handler
Triggered when the onload () page is loaded
Triggered when the onUnload () page is closed

 

Difference: you cannot change document. Location (because this is the location of the currently displayed document ). However, you can change window. Location (Replace the current document with other documents). Window. Location is an object, and document. location is not an object.

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.