[JavaScript] Segment transitions the Chinese string of the client into UTF-8 code development ASP.NET, I often want to be on the client
Using Window.Location = 'WebForm1.aspx? param1 = Chinese string' in JavaSPX? PARAM1 = Chinese string ', but must convert the Chinese string into UTF-8 before jump, otherwise there is existence in the middle of the Chinese string Characters such as spaces will cause problems.
In fact IE 5.5 , Netscape 6 , Mozilla already has a conversion function, which is Encodeuricomponent, but you need code for a low version of browser. / * ********************************************************** MOST OF this code WAS Kindly ** provided to me by ** Andrew Clover (and At DoXDesk Dot COM) ** http://and.doxdesk.com/; ** in response to my plea in my blog at ** http://worldtimzone.com/blog/date/2002/09/24* IT Was unclear WHETHER He Created It. * / Function UTF8 (Wide) {var C, S; VAR ENC = ""; VAR i = 0; While (i
VAR HEXCHARS = "0123456789AbcDef";
Function tohex (n) {return hexchars.charat (n >> 4) hexchars.charat (n & 0xf);}
var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 _-"; function encodeURIComponentNew (s) {var s = utf8 (s); var c; var enc = ""; for (var i = 0; i Function urlencode (fld) {if (FLD == ") Return False; var encodedfield =" "; var s = fld; if (typeof encodeuricomponent ==" function ") {// use javascript built-in function // ie 5.5 and Netscape 6 and Mozilla encodedField = encodeURIComponent (s);} else {// Need to mimic the javascript version // Netscape 4 and IE 4 and IE 5.0 encodedField = encodeURIComponentNew (s);} // alert ( "New Encoding: " Encodeuricomponentnew (FLD) //" / n escape (): " escape (fld); return encodedfield;}