When passing parameters from page A to page B through A url, Chinese garbled characters occur when obtaining URL parameters. The correct method for parsing url parameters is as follows, if you are interested, you can refer to the following two methods to parse url parameters when passing parameters to page B through url on page:
Method 1: Regular Expression Analysis
The Code is as follows:
Function getQueryString (name ){
Var reg = new RegExp ("(^ | &)" + name + "= ([^ &] *) (& | $)", "I ");
Var r = window. location. search. substr (1). match (reg );
If (r! = Null) return unescape (r [2]); return null;
}
Call this method as follows:
The Code is as follows:
Alert (GetQueryString ("parameter name 1 "));
Alert (GetQueryString ("parameter name 2 "));
Alert (GetQueryString ("parameter name 3 "));
Method 2:
The Code is as follows:
Call this method as follows:
The Code is as follows:
If the parameter contains Chinese characters, perform the encoding and decoding:
The Code is as follows:
1. parameter passing page
Javascript code: