Solved

Writing Special Characters to Cookies

Posted on 2001-07-16
7
198 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

743 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

11 Experts available now in Live!

Get 1:1 Help Now