Encodeuri ()The function can encode a string as a URI.
This method does not encode ASCII letters and numbers, and does not encode these ASCII punctuation marks :-_.! ~ *'().
The purpose of this method is to fully encode the URI. Therefore, the encodeuri () function will not escape the following ASCII punctuation marks with special meanings in the URI :;/? : @ & =+ $ ,#
In this example, zhogn uses encodeuri () to encode the URI:
<SCRIPT type = "text/JavaScript"> document. write (encodeuri ("http://www.w3school.com.cn") + "<br/>") document. write (encodeuri ("http://www.w3school.com.cn/My first/") document. write (encodeuri (",/? : @ & =+ $ # ") </SCRIPT>
Output:
Http://www.w3school.com.cnhttp: // www.w3school.com.cn/my%20first /,/? : @ & =+ $ #
Encodeuricomponent ()The function can encode a string as a URI component.
This method does not encode ASCII letters and numbers, and does not encode these ASCII punctuation marks :-_.! ~ *'().
Other characters (such :;/? : @ & =+ $, # The punctuation marks used to separate URI components) are all replaced by one or more hexadecimal escape sequences.
In this example, we will use encodeuricomponent () to encode the URI:
<SCRIPT type = "text/JavaScript"> document. write (encodeuricomponent ("http://www.w3school.com.cn") document. write ("<br/>") document. write (encodeuricomponent ("http://www.w3school.com.cn/P 1/") document. write ("<br/>") document. write (encodeuricomponent (",/? : @ & =+ $ # ") </SCRIPT>
Output:
HTTP % 3A % 2f % 2fwww.w3school.com. cnhttp % 3A % 2f % 2fwww.w3school.com.cn % 2fp % 201% 2f % 2C % 2f % 3f % 3A % 40% 3D % 2B % 26% 23
Note the differences between the encodeuricomponent () function and the encodeuri () function. The former assumes that its parameters are part of the URI (such as the protocol, host name, path, or query string ). Therefore, the encodeuricomponent () function uses escape characters to separate the punctuation marks of each part of the URI.