[JavaScript] Segment transition to UTF-8 code in a paragraph

xiaoxiao2021-03-06  70

[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 = 0xDC00 && c <0xe000) Continue; if (c> = 0xD800 && c <0xdc00) {if (i> = wide.length) Continue; s = wide.charcodeat (i ) ; If (s <0xDC00 || C> = 0xDE00) Continue; c = ((C-0xD800) << 10) (S-0XDC00) 0x10000;} // Output Value IF (c <0x80) ENC = String.fromcharcode (c); Else IF (c <0x800) ENC = String.Fromcharcode (0xc0 (C >> 6), 0x80 (C & 0x3F)); ELSE IF (c <0x10000) ENC = String.Fromcharcode (0xE0 (C >> 12), 0x80 (c >> 6 & 0x3f), 0x80 (C & 0x3F)); Else Enc = String.Fromcharcode (0xF0 (C >> 18), 0x80 (C >> 12 & 0x3f), 0x80 (c >> 6 & 0x3F), 0x80 (C & 0x3F));} Return E NC;}

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;}

转载请注明原文地址:https://www.9cbs.com/read-90634.html

New Post(0)