Introduction to JavascriptURI parsing _ javascript skills

Source: Internet
Author: User
This article mainly introduces the introduction of JavascriptURI parsing. This article provides sample code directly. if you need a friend, you can refer to parsing URI as an interesting thing. I didn't realize it before, it turns out this thing can be so complicated.

URI

In Wikipedia, URI is interpreted as follows:

The 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

The 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.jb51.net/search? Q = js & type =
Then you have

The code is as follows:


Var parser = document. createElement ('A ');
Parser. href = "http://www.jb51.net/search? Q = js & type ="


We can know the protocol, port number, host, and specific address.

The code is as follows:


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


The returned result is

The 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

The code is as follows:


Mailto: h@jb51.net? Subject = hello


So

The 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"

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.