Solved

Writing Special Characters to Cookies

Posted on 2001-07-16
7
203 Views
Last Modified: 2006-11-17
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.
0
Comment
Question by:kenchan2000
  • 4
  • 2
7 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 6285525
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
 

Author Comment

by:kenchan2000
ID: 6286580
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
 
LVL 33

Accepted Solution

by:
knightEknight earned 100 total points
ID: 6286899
You may have to do this from the server instead:

document.write(escape('<%=Server.URLEncode(Chr(i))%>'));
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 33

Expert Comment

by:knightEknight
ID: 6286904
... or just:

document.write('<%=Server.URLEncode(Chr(i))%>');
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6287048
Assuming that the questioner can use ASP...
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 6287360
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
 
LVL 33

Expert Comment

by:knightEknight
ID: 6287369
Or, do a pure javascript solution on the client:

<SCRIPT language='javascript'>

for ( i=0; i<128; i++ )
{
  document.writeln( String.fromCharCode(i) );
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now