kenchan2000
asked on
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.
The problem is that Javascript automatically converts some special characters before writing to the cookie.
ASKER
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().
but
when I output something using ASP like
<%
For i=0 To 127
%>
<script languagte="javascript">
document.write(escape('<%=
</script>
<%
Next
%>
Special char cannot be escape().
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
... or just:
document.write('<%=Server. URLEncode( Chr(i))%>' );
document.write('<%=Server.
Assuming that the questioner can use ASP...
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
%>
Simpler perhaps is this:
<%
For i=0 To 127
response.write "'" & Server.URLEncode(Chr(i)) & "'<BR>" & vbCrLf;
Next
%>
Or, do a pure javascript solution on the client:
<SCRIPT language='javascript'>
for ( i=0; i<128; i++ )
{
document.writeln( String.fromCharCode(i) );
}
<SCRIPT language='javascript'>
for ( i=0; i<128; i++ )
{
document.writeln( String.fromCharCode(i) );
}
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