JS URL to pass the Chinese parameter garbled, how to get the URL parameter problem

Source: Internet
Author: User

A: JS URL to pass the Chinese parameter garbled problem, Focus: encodeURI encoding, decodeURI decoding:

1. Pass the reference 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. Receive Parameters page: test02.html

<script>
var urlinfo = window.location.href;//Fetch URL
var userName = Urlinfo.split ("?") [1].split ("=") [1];//split URL to get the "=" side of the parameters
$ ("#userName"). HTML (decodeURI (userName));
</script>
Two: How to get the url "? "After," = "parameter value:

A. First get the full URL value with Window.location.href.
B. Using split to intercept "?" After the all
C.split ("?") number in [1] later, calculated by default starting from 0

Three: JS in the escape,unescape,encodeuri,encodeuricomponent difference:

1. Pass parameters when used, encodeuricomponent otherwise the URL is easily "#", "?" "," & "and other sensitive symbols partition.
2.url Jump time use, encoding with encodeURI, decoding with decodeURI.
3.escape () Just for the 0-255 ASCII characters to do the conversion work, converted to%u**** such a code, if you want to use more words such as UTF-8 word repertoires must use encodeURIComponent () or encodeURI () conversion can be% Nn%nn This code can, in other cases escape,encodeuri,encodeuricomponent encoding results are the same, so for the global unification process, in the use of encodeURIComponent () or encodeURI () instead Escape () Use it!

Can be reproduced arbitrarily, please be sure to use hyperlinks in the form of the original source of the article and this statement

This address: http://www.weiking.com.cn/post/654.html

JS URL to pass the Chinese parameter garbled, how to get the URL parameter problem

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.