The difference Analysis _javascript skill of window.location and document.location

Source: Internet
Author: User
Document.location This object contains information about the current URL
Location.host Get the port number
Location.hostname set or get host name
Location.href set or get the entire URL
Location.port Sets or gets the port number of the URL
Location.search Sets or gets the part of the HREF attribute that follows the question mark
-------------------------------------------------------------------------------
The application of window.location in JS
URL is: Uniform Resource Locator (uniform Resource Locator, URL)
The complete URL is composed of these parts:
Scheme://host:port/path?query#fragment
Scheme: Communication protocol
Commonly used Http,ftp,maito, etc.
Host: Hosts
Server (computer) domain Name System (DNS) host name or IP address.
Port: Port number
Integer, optional, omit when using the default port of the scheme, such as HTTP's default port is 80.
Path: Paths
A string separated by 0 or more "/" symbols, typically used to represent a directory or file address on a host.
Query: Querying
Optional for dynamic Web pages, such as using CGI, ISAPI, php/jsp/asp/asp. NET, and other technology-made pages, can have multiple parameters, separated by the "&" symbol, and the name and value of each parameter are separated by the "=" symbol.
Fragment: Pieces of information
A string that specifies the fragment in the network resource. For example, a Web page has multiple noun interpretations, which can be directly positioned to a noun interpretation using fragment. (also known as anchor points.)
For such a URL
Http://www.x2y2.com:80/fisker/post/0703/window.location.html?ver=1.0&id=6#imhere
We can use JavaScript to get every part of it.
1, Window.location.href
Entire URL string (in the browser is the complete address bar)
This example returns a value of: Http://www.x2y2.com:80/fisker/post/0703/window.location.html?ver=1.0&id=6#imhere
2,window.location.protocol
The protocol part of the URL
This example returns the value: http:
3,window.location.host
Host part of URL
This example returns a value of: www.x2y2.com
4,window.location.port
Port portion of URL
If the default 80 port (update: Even if added: 80), then the return value is not the default of 80 but null characters
This example returns the value: ""
5,window.location.pathname
The path portion of the URL (that is, the file address)
This example returns a value of:/fisker/post/0703/window.location.html
6,window.location.search
Query (Parameters) Section
In addition to assigning values to dynamic languages, we can also give static pages and use JavaScript to get the value of a parameter that is believed to be
This example returns a value:? ver=1.0&id=6
7,window.location.hash
Anchor Point ==========================================
document.href= "Http://www.jb51.net"
document.location= "Http://www.jb51.net"
window.location= "Http://www.jb51.net"
It's just a matter of inclusion.
One is window, one is document
Location is an object such as the Document.location and Window.location properties of this page have
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:
The attribute category that the href is location to be visible is string.
[Document Object]
This object is a property of the window and frames objects, and is a document that is displayed in a Windows or frame.
Property
Alinkcolor Active link color (ALINK)
Anchor a HTMI anchor point, created using the <a name=> tag (the property itself is also an object)
The anchors array lists the arrays of document anchor objects (<a name=>) (the property itself is also an object)
BgColor the background color of the document (bgcolor)
A cookie is a piece of information stored in a cookie.txt file, which is a property of the Document object
Text color of Fgcolor document (text attribute in <BODY> tag)
A form (<FORM>) in the form document (the property itself is also an object)
Forms Anay lists an array of form objects (the property itself is an object) in the order in which they appear in the document
LastModified the last modified date of the document
The color of the link in the LinkColor document, that is, the link attribute in the <BODY> tag (linked to a document that the user has not observed)
A <a href=> tag in the link document (the property itself is also an object)
An array of link objects in the Links array document, arranged in the order in which they appear in the document (the property itself is an object)
Location The URL of the currently displayed document. The user cannot change the document.location (because this is where the document is currently displayed). But
Can change window.location (replace the current document with other documents) window.location itself is an object, and
Document.location is not an object
Referrer contains the URL of the linked document that the user clicks to reach the current document
Title of document ((title>)
Vlinkcolor link text color that points to a document that the user has observed, that is, the vlink characteristics of the <BODY> tag
Method
Clear clears the contents of the specified document
Close closes the document flow
Open Document Flow
Write writes text to a document
Writeln writes text to the document and ends with a newline character.
[Window Object]
It is a top-level object, not another object's property, the browser's window.
Property
Defaultstatus The default status bar message
Document that is currently displayed (the property itself is also an object)
A frame in the frame window ((frame>) (the property itself is also an object)
The frames array enumerates the arrays of frame objects for the window, listed in the order in which they appear in the document (the property itself is also a
Object
The history list of the History window (the property itself is also an object)
Number of frames in length window
The full (absolute) URL of the document displayed in the Location window (the property itself is also an object) do not put it in the same way as the document.location
Confusion, which is the URL of the currently displayed document. Users can change window.location (replace the current document with another document), but they cannot change
Document.location (because this is where the document is currently displayed)
When the name window is open, give the name of the window
Opener represents the window that uses window.open to open the script for the current window (this is the Netscape Navigator 3.0beta 3 cited
A new attribute to enter)
Parent contains a synonym for the window for the current frame. A property of the frame and window objects
Self synonyms for the current window or frame
The message in the Status State bar
Top contains synonyms for the topmost browser window for the current frame
window or a synonym for the frame, same as self
Method
Alert () Opens an alert message box
Cleartimeout () Work to terminate the SetTimeout method
Close () Closes the window
Confirm () Opens a Confirm message box where the user can select OK or Cancel, and if the user clicks OK, the method returns True, click
Cancel returns False
Blur () move focus away from the specified window (this is the new method introduced by Netscape Navigator 3.0 Beta 3)
Focus () Bring the specified window to the foreground (another new method)
Open () Opens a new window
Prompt () Opens a prompt dialog box that allows users to type text into the box and return typed text to the script
SetTimeout () waits a specified number of milliseconds, and then runs the directive event handler event handler
Onload () page loads when triggered
Onunload () trigger when page closes
Difference: The user cannot change the document.location (because this is where the document is currently displayed). However, you can change window.location (replacing the current document with other documents) window.location itself 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.