Writing Special Characters to Cookies

How can I write all characters with Char Code (0-127) to a cookie and get all them without error using Javascript?

The problem is that Javascript automatically converts some special characters before writing to the cookie.
kenchan2000Asked:
Who is Participating?
 
knightEknightConnect With a Mentor Commented:
You may have to do this from the server instead:

document.write(escape('<%=Server.URLEncode(Chr(i))%>'));
0
 
CJ_SCommented:
you can use the escape and unescape functions

myvariable = escape(myvariable)
// now write myvariable to cookie

will convert the data to, for the browser, readable code.

When you have rtetrieved the value from the cookie you do:
// cookie value retrieved in myvariable
myvariable = unescape(myvariable)

regards,
CJ
0
 
kenchan2000Author Commented:
I decide to use escape()
but
when I output something using ASP like
<%
For i=0 To 127
   %>
<script languagte="javascript">
document.write(escape('<%=Chr(i)%>'));
</script>
   <%
Next
%>
Special char cannot be escape().
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
knightEknightCommented:
... or just:

document.write('<%=Server.URLEncode(Chr(i))%>');
0
 
CJ_SCommented:
Assuming that the questioner can use ASP...
0
 
knightEknightCommented:
true, I assumed that from his (another assumption) second comment.  

Simpler perhaps is this:

<%
For i=0 To 127
  response.write "'" & Server.URLEncode(Chr(i)) & "'<BR>" & vbCrLf;
Next
%>
0
 
knightEknightCommented:
Or, do a pure javascript solution on the client:

<SCRIPT language='javascript'>

for ( i=0; i<128; i++ )
{
  document.writeln( String.fromCharCode(i) );
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.