JS gets the parameter in the URL and when the parameter is Chinese, it is decoded by JS

Source: Internet
Author: User
Tags hash split vars

This article mainly introduces the URL in the transfer of Chinese parameters through JS decoding, the need for friends can refer to the

If the parameter passed is: code as follows: <a href= "${pagecontext.request.contextpath}/productdisplay/productdisplay_ Productdisplayui.action?pkid=${pkid}&name=${name} "style=" Color:white; margin-top:10px; margin-bottom:10px; "  >${name}</a> get the URL parameters of JS as follows: The code is as follows:/** initialization load end/function Geturlvars () {var vars = [], hash; var hashes = Window.location.href.slice (Window.location.href.indexOf ('? ')  +1). Split (' & ');  for (var i = 0; i < hashes.length i++) {hash = hashes[i].split (' = ');  Vars.push (Hash[0]);  Vars[hash[0]] = hash[1];  return vars;  If there is Chinese in the URL, then the parameters will have Chinese garbled, you have to use decodeURI () method to decode, the following: The code is as follows://Get the category of pkid var params = Geturlvars ();  Get the ID of this category var parentid = params[params[0]]; Get the category name var productName = decodeURI (params[params[1]);

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.