Differences between window. location and document. location _ javascript skills

Source: Internet
Author: User
Tags time in milliseconds
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 itself is also an object, and document. location is not an object 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 in js
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. href = "http://www.jb51.net"
Document. location = "http://www.jb51.net"
Window. location = "http://www.jb51.net"
Only included issues
One is window and the other is document.
Location is an object. For example, the attributes of document. location and window. location on this page include:
Location. hostname = community.csdn.net
Location. href = http://community.csdn.net/Expert/topic/4033/4033372.xml? Temp = 2.695864E-02
Location. host = community.csdn.net
Location. hash =
Location. port =
Location. pathname =/Expert/topic/4033/4033372 .xml
Location. search =? Temp = 2.695864E-02
Location. protocol = http:
It can be seen that the property category of href is location is string.
[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 using a tag (this attribute is also an object)
Anchors array lists the array () of document anchors (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.
The text color of the fgColor document (TEXT features in the mark)
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 isLINK feature in tag (LINK to document not observed by the user)
A tag 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 isMarked VLINK features
Method
Clear the content of a specified document
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.