When parameters are submitted between different websites. For example, if website A is A UTF-8 code, submit A link to bkjia.com (GBK)
Http://s.bkjia.com /? Q = Cup & sp = on will cause transcoding problems. Provides a function. To http://s.bkjia.com /? Q = 1 & a = 2 & B = 3 & c = 4 convert to FORM, and then change FORM's accept-charset to achieve automatic transcoding.
The Code is as follows:
Copy to ClipboardReference content: [www.bkjia.com] // provides a URL for submitting the JS analysis creation form
Function submitAsForm (requestUri, charset ){
Var s = requestUri. split ('? '), D = document, div = d. createElement ('div ');
Div. innerHTML =
'<Form method = "GET" action = "' + s [0] + '">' +
S [1]. replace (/\ B (\ w +) \ = (.*?)) (& | $)/Gi, function (s, m, n, v ){
Return '<input type = "hidden" name = "' + n + '" value = "' +/* encodeURIComponent */(v) + '"/>'
}) +
'</Form>'
Var form = div. firstChild;
Form. setAttribute ('Accept-charset', charset | 'utf-8 ');
If (document. all) document. charset = charset;
Form. submit ();
}
// SubmitAsForm ('HTTP: // s.bkjia.com /? A = 1 & B = 2 & c = 3 & d = 4', 'gb2312 ')