JS URL to pass the Chinese parameter garbled processing

Source: Internet
Author: User

Original: JS URL to pass the Chinese parameter garbled processing

The address shown in the browser is this:

But the address that was debugged by F12 changed:

This must be because the browser is encoding the URL path by default. The problem is that when we go to the value, we get a bunch of weird stuff back there. We don't get the value we want. What do we do? Here is only their own solution, perhaps not universal, share with you, there is a better way to sue me.

Get the value in the URL
functionrequest (paras) {varURL =Location.href; varparastring = url.substring (Url.indexof ("?") +1,url.length). Split ("&"); varParaobj = {};  for(vari=0; J=parastring[i]; i++) {paraobj[j.substring (0,j.indexof ("=")). toLowerCase ()] = j.substring (j.indexof ("=") +1, j.length); }      varReturnValue =paraobj[paras.tolowercase ()]; if(typeof(returnvalue) = = "Undefined"){          return""; }Else{          returnreturnvalue; } }   functionGethys () {if(Request (' Hys ')! = ") {

Decodeurl the Chinese and decoding the passing party
  var hys=decodeuri (Request (' Hys '));    var select =document.getelementbyid (' Nybgs ');    var selectvalue= "";     for (var i=0;i<select.options.length;i++) {   Selectvalue=select.options[i].value;    If(document.getElementById (' Nybgs '). options[i].value==hys) {    document.getElementById (' Nybgs '). SelectedIndex = i;     }}}

The request method is the method of taking the parameter in the address, and the decodeURI () method is to decode the Chinese of the passing party.

In Firefox and 360 and IE8 tested, no problem, do not know if you have any other better way?

JS URL to pass the Chinese parameter garbled processing

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.