Solved

Writing Special Characters to Cookies

Posted on 2001-07-16
7
207 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

860 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