Home > Article > Web Front-end > Introduction to Javascript URI parsing_javascript skills
Parsing URI is an interesting thing. I didn’t realize before that it can be so complicated.
URI
The explanation of URI in Wikipedia is as follows:
Quoted from the explanation of URI composition on the Internet, and these can be seen in the analysis of URI later.
URI generally consists of three parts:
1. Naming mechanism for accessing resources.
2. The host name where the resources are stored.
3. The name of the resource itself, represented by the path.
Or it can be said that the two seem to be consistent.
The format of the URL consists of the following three parts:
1. Agreement (or service method)
2. The IP address of the host where the resource is stored (sometimes including the port number)
3. The specific address of the host resource. , such as directory and file names, etc.
URI parsing
Javascript URI parsing
Simply take the search JS in the blog as an example, the following is its URL,
http://www.jb51.net/search/?q=js&type=
Then there was
If it is a URI for an email, assuming the URI is
> parser.protocol
"mailto:"
> parser.pathname
"h@jb51.net"
> parser.search
"?subject=hello"