Solved

Writing Special Characters to Cookies

Posted on 2001-07-16
7
209 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery Datatables.js Selecting a Row to get ID 5 37
Send form to asp server side 6 28
Link not working 6 44
testing a web application for ipad on windows pc 3 41
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-…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

696 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