"Enoch Chan" <si****@hotmail .com> wrote in message news:<ck******* **@imsp212.netv igator.com>...
I would like to set a Session variable to a value. In Vbscript it should be
What do you mean by session variable?
Javascript has global variables. You can access global variables from
any child frame or child window.
Javascript has session cookies. You can save small amount of data in a
cookie. I have had problems with session cookies in IE and do not use
session cookies any more. Session cookies are cookie that do not
include a time value. Instead, I set an expiration time on the cookies
I create.
I suggest using an existing set of cookie routines. The
document.cookie can contain existing cookies.
~kaeli~ has developed some cookie code. You may view it in this
article:
http://groups.google.com/groups?hl=e...859-1&selm=MPG
..1af96c2a4f8ab c94989dcc%40nnt p.lucent.com
Also, ~kaeli~ reports that:
There's some even better code that sets more cookie properties like
domain, secure, path, etc here.
http://www.acm.uiuc.edu/webmonkeys/j...ipt/cookies.js
I wrote a short program for verifying cookies will work on a site.
The cookie code was taken from:
Functions from Using HTML 4, Java 1.1, and JavaScript 1.2:
Complete. Definitive. Invaluble.
by Eric Jim O'Donnell, et al.
and from the Netscape develper's site.
Robert
Here is my cookie testing
code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>Rememb er by cookie</title>
<script type="text/javascript">
// Sets cookie values. Expiration date is optional
//
function setCookie(name, value, expire) {
document.cookie = name + "=" + escape(value)
+ ((expire == null) ? "" : ("; expires=" + expire.toGMTStr ing()))
}
function getCookie(Name) {
var search = Name + "="
if (document.cooki e.length > 0) { // if there are any cookies
offset = document.cookie .indexOf(search )
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie .indexOf(";", offset)
// set index of end of cookie value
if (end == -1)
end = document.cookie .length
return unescape(docume nt.cookie.subst ring(offset, end))
}
}
}
function deleteCookie(na me,path,domain) {
if (getCookie(name )) document.cookie = name + "=" +
( (path) ? ";path=" + path : "") +
( (domain) ? ";domain=" + domain : "") +
";expires=T hu, 01-Jan-70 00:00:01 GMT";
}
function registerCookie( cookieName,cook ieValue) {
var today = new Date()
var expires = new Date()
expires.setTime (today.getTime( ) + 1000*60*60*24*3 65)
setCookie(cooki eName, cookieValue, expires)
}
</script>
<body>
<p>Let's see if we can set then read a cookie
<script type="text/javascript">
document.write( "when on (document.url) " + document.URL);
document.write( "</p>");
var all = "I hope this cookie doesn't crumble.";
document.write( "<p>");
document.write( "document.cooki e before deleteCookie = "
+ document.cookie + "<br><br>") ;
deleteCookie("m ycookietry");
document.write( "document.cooki e after deleteCookie= "
+ document.cookie + "<br><br>") ;
registerCookie( "mycookietry",a ll);
document.write( "document.cooki e after registerCookie = "
+ document.cookie + "<br><br>") ;
theMessage = getCookie("myco okietry");
document.write( "theMessage = " + theMessage + "<br>");
document.write( "</p>");
</SCRIPT>
</body>
</html>