I. garbled characters are transmitted in JS URLs. Key points: encodeuri encoding and decodeuri decoding:
1. parameter passing page
JavaScript code: <SCRIPT type = "text/JavaScript"> // <! [CDATA [
Function send (){
VaR url = "test01.html ";
VaR username = $ ("# username" ).html ();
Window. Open (encodeuri (URL + "? Username = "+ username ));}
//]>
</SCRIPT>
2. Receiving parameters page: test02.html
<SCRIPT>
VaR urlinfo = Window. Location. href; // retrieve the URL
VaR username = urlinfo. Split ("?") [1]. Split ("=") [1]; // The number of shards after the split URL is "="
Users (includomainusernamedomain.html .html (decodeuri (username ));
</SCRIPT>
Ii. How to obtain the URL "?" Then, the "=" parameter value:
A. First, use window. Location. href to get all URL values.
B. Use split to intercept "?" All
C. Split ("?") The number in [1] after it is calculated from 0 by default.
Iii. Differences between escape, Unescape, encodeuri and encodeuricomponent in JS:
1. When passing parameters, encodeuricomponent. Otherwise, the URL is easily marked "#","?"," And other sensitive symbols.
2. Used for URL jump, encoding using encodeuri, and decoding using decodeuri.
3. Escape () is only for ASCII characters other than 0-conversion, converted to % u *** such code, if you want to use more characters such as UTF-8 Character Library
You must use encodeuricomponent () or encodeuri () to convert it to % NN.
This code can be used. In other cases, escape, encodeuri, and encodeuricomponent have the same encoding results. Therefore, for the global unification process
Use encodeuricomponent () or encodeuri () instead of escape!
You can reprint it as needed. During reprinting, be sure to mark the original source of the article and the statement in the form of a hyperlink.
Address: http://www.weiking.com.cn/post/654.html