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: Hosts
The server (computer) domain Name System (DNS) hostname or IP address. Port: Port number
An integer, optionally, that omits the default port for using the scenario, such as HTTP, with the default port of 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 use with dynamic Web pages such as CGI, ISAPI, php/jsp/asp/asp. NET and other technical Web pages) pass parameters, can have multiple parameters, separated by the "&" symbol, the name and value of each parameter is separated by the "=" symbol. Fragment: Pieces of information
String that specifies the fragment in the network resource. For example, there are multiple noun interpretations in a Web page, and you can use fragment to navigate directly to a noun interpretation. (also known as anchor points.) For such a urlhttp://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
The entire URL string (in the browser is the full address bar)
This example returns the value: Http://www.x2y2.com:80/fisker/post/0703/window.location.html?ver=1.0&id=6#imhere2,
Window.location.protocol
of the URL
ProtocolPart
This example returns the value: Http:3,
Window.location.host
of the URL
HostPart
This example returns the value: WWW.X2Y2.COM4,
Window.location.port
of the URL
PortPart
If you are using the default 80 port (update: Even if you added: 80), the return value is not the default of 80 but the null character
This example returns the value: "" 5,
Window.location.pathname
The path portion of the URL (that is, the file address)
This example returns the value:/FISKER/POST/0703/WINDOW.LOCATION.HTML6,
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 values of the arguments we believe in.
This example returns the value:? ver=1.0&id=67,
Window.location.hash
Anchor Point
This example returns the value: #imhere 8,window.location.pathname.indexof ("Cesu") > 0 query whether the URL path contains a name the return value of this example: false
JavaScript Tutorial: Getting the current address bar URL