1. Get URL
You can directly use location to obtain the URL. Window. Location or window. loation. href can also be used.
2. Analyze the URL
If the attribute of the URL obtained using location is an object, you need to convert it into a string for string analysis.
Use location for processing, first convert it to a string, use the tostring () function, URL. tostring ();
Some URL parameters
The complete URL consists of the following parts:
Scheme: // host: Port/path? Query # Fragment
Scheme = communication protocol (Common HTTP, FTP, Maito, etc)
Host = host (domain name or IP address)
Port = port number
Path = path
Query = Query
Optional. Used for dynamic web pages (such as CGI, ISAPI, PHP/JSP/asp. net and other technologies) Transfer Parameters. Multiple parameters can be separated by the "&" symbol. The names and values of each parameter 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.master8.net: 80/SEO /? 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)
2, window. Location. Protocol
URL protocol section
Returned value in this example: http:
3, window. Location. Host
Host part of the URL
Returned value in this example: www.master8.net
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:/SEO/
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
Returned value in this example: # imhere