This article mainly describes how to decode the url through js when passing Chinese parameters. For more information, see if the parameters are:
The Code is as follows:
$ {Name}
The js for getting url parameters is as follows:
The Code is as follows:
/** Initialize the end of loading */
Function getUrlVars (){
Var vars = [], hash;
Var hashes = window. location. href. slice (window. location. href. indexOf ('? ') + 1). split ('&');
For (var I = 0; I Hash = hashes [I]. split ('= ');
Vars. push (hash [0]);
Vars [hash [0] = hash [1];
}
Return vars;
}
If the url contains Chinese characters, Chinese characters are garbled during parameter fetch. decode the url using the decodeURI () method as follows:
The Code is as follows:
// Obtain the pkId of the category
Var params = getUrlVars ();
// Obtain the category id
Var parentId = params [params [0];
// Obtain the category name
Var productName = decodeURI (params [params [1]);