Introduction to Javascript URI parsing

Source: Internet
Author: User

URI

In Wikipedia, the explanation for URIs is this:

In computer terminology, a Uniform Resource identifier (Uniform Resource Identifier, or URI) is a string that identifies the name of an Internet resource. This type of identification allows users to interact with resources in the network (generally referred to as the World Wide Web) through specific protocols. The URI is defined by a scheme that includes a determination of syntax and related protocols.

This is the interpretation of the URI composition on the network, which can be seen later in the parsing of the URI.

URIs are generally made up of three parts:

1. Access the resource naming mechanism.
2. Host name of the resource to be stored.
3. The name of the resource itself, represented by the path.

Or it could be that way, the two seem to be the same.

The format of the URL consists of the following three parts:

1. Agreement (or service mode)
2. Host IP address (sometimes including port number) for this resource
3. The specific address of the host resource. , such as directory and file name

URI parsing

"Parsing" a URI means converting a relative URI reference to an absolute form, or by trying to get a solvable URI or a resource represented by a URI reference to dereference the URI. The "parsing" section of the document processing software typically provides both of these features.

Javascript URI parsing

Simply take the blog search JS as an example, the following is its URL,

Http://www.jb51.net/search/?q=js&type=
And then there's the

The code is as follows:

var parser = document.createelement (' a '= "Http://www.jb51.net/search/?q=js&type="

We can know its protocol, port number, host, specific address, etc.

The code is as follows:

Parser.protocol; Parser.host; Parser.pathname; Parser.search;

Results returned:

protocol:http host:www.jb51.net Pathname:/search/ search:? q=js&type=

The above result is a complete URI. Just for Parser.search this part is not very understanding, for the number, should be the parameter, for the search parameters. If it is a URI for a message, assume that the URI is:

Mailto:[email Protected]?subject=hello

So:

var parser = document.createelement (' a '= "Mailto:[email Protected]?subject=hello">  "mailto:" >"[email protected]" >"Subject=hello"

Reprint Address: http://www.jb51.net/article/62254.htm

Introduction to Javascript URI parsing

Related Article

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.