JS get current URL address parameter Chinese garbled problem

Source: Internet
Author: User

On the Internet to read some articles on this issue, are said not clear, some is a mess, completely unable to see, so found a can use, reference as a note.

First get the Address bar information to the current page var url = window.location.href;//Get the URL address var obj = {};//The object to be used to hold the parameter var reg =/\?/; intercept if (Url.match ( REG) {    //To determine incoming parameters, to intercept with question marks, after the question mark is the parameter    var chars = Url.split ('? ') [1];    var arr = chars.split (' & ');//Intercept &    //Get truncated array as key value pair string for    (var i = 0; i < arr.length; i++) {        //Conservative point OK See if the Name=value form is        var num = arr[i].indexof ("=");        if (num > 0) {            //concatenation string            var name = arr[i].substring (0, num);            var value = arr[i].substr (num + 1);            Splicing object, and transcoding            obj[decodeuricomponent (name)] = decodeuricomponent (value);}}}    Console.log (obj);

So you can use it.

js get the current URL address parameter Chinese garbled 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.