Introduction to Javascript URI parsing, javascripturi
Parsing URI is an interesting thing. I didn't realize it before. It could be so complicated.
URI
In Wikipedia, URI is interpreted as follows:
Copy codeThe Code is as follows:
In computer terms, a unified Resource Identifier (Uniform Resource Identifier or URI) is a string used to identify an Internet Resource Name. This identifier allows users to interact with resources on the Network (generally the World Wide Web) through a specific protocol. A URI is defined by a scheme that includes a definite syntax and related protocols.
The description of URI composition on the network, which can be seen later in URI parsing.
A URI consists of three parts:
1. Resource Access naming mechanism.
2. Host Name for storing resources.
3. The name of the resource, represented by the path.
Or, it can be said that the two seem the same.
The URL format consists of the following three parts:
1. Protocol (or service method)
2. Host IP addresses (sometimes including port numbers) that store the resource)
3. The specific address of the host resource ., Such as directories and file names
URI Parsing
Copy codeThe Code is as follows:
"Parsing" a URI means converting a relative URI reference to an absolute form, or resolving the reference by trying to obtain a resource that can be referenced by a referenced URI or a referenced URI. The parsing section of the document processing software usually provides both features.
Javascript URI Parsing
Simply search for JS in a blog as an example, the following is its URL,
Http://www.bkjia.com/search? Q = js & type =
Then you have
Copy codeThe Code is as follows:
Var parser = document. createElement ('A ');
Parser. href = "http://www.bkjia.com/search? Q = js & type ="
We can know the protocol, port number, host, and specific address.
Copy codeThe Code is as follows:
Parser. protocol;
Parser. host;
Parser. pathname;
Parser. search;
The returned result is
Copy codeThe Code is as follows:
Protocol: http
Host: www.jb51.net
Pathname:/search/
Search :? Q = js & type =
The above result is a complete URI. I just don't really understand this part of parser. search? It should be a parameter used for search.
For the URI of an email, assume that the URI is
Copy codeThe Code is as follows:
Mailto: h@jb51.net? Subject = hello
So
Copy codeThe Code is as follows:
Var parser = document. createElement ('A ');
Parser. href = "mailto: h@jb51.net? Subject = hello ";
> Parser. protocol
"Mailto :"
> Parser. pathname
H@jb51.net"
> Parser. search
"? Subject = hello"