By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,934 Members | 1,449 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,934 IT Pros & Developers. It's quick & easy.

Session variable

P: n/a
I would like to set a Session variable to a value. In Vbscript it should be

Session("ZoomValue")=500

How can I set this session variable by using Javascript?

Thanks
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Tue, 12 Oct 2004 20:56:52 +0800, "Enoch Chan" <si****@hotmail.com>
wrote:
I would like to set a Session variable to a value. In Vbscript it should be

Session("ZoomValue")=500

How can I set this session variable by using Javascript?


Session.ZoomValue=500

Jim.
Jul 23 '05 #2

P: n/a
"Enoch Chan" <si****@hotmail.com> wrote in message news:<ck*********@imsp212.netvigator.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
..1af96c2a4f8abc94989dcc%40nntp.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>Remember 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.toGMTString()))
}
function getCookie(Name) {
var search = Name + "="
if (document.cookie.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(document.cookie.substring(offset, end))
}
}
}

function deleteCookie(name,path,domain) {
if (getCookie(name)) document.cookie = name + "=" +
( (path) ? ";path=" + path : "") +
( (domain) ? ";domain=" + domain : "") +
";expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function registerCookie(cookieName,cookieValue) {
var today = new Date()
var expires = new Date()
expires.setTime(today.getTime() + 1000*60*60*24*365)
setCookie(cookieName, 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.cookie before deleteCookie = "
+ document.cookie + "<br><br>");
deleteCookie("mycookietry");
document.write("document.cookie after deleteCookie= "
+ document.cookie + "<br><br>");

registerCookie("mycookietry",all);

document.write("document.cookie after registerCookie = "
+ document.cookie + "<br><br>");

theMessage = getCookie("mycookietry");
document.write("theMessage = " + theMessage + "<br>");
document.write("</p>");
</SCRIPT>
</body>
</html>
Jul 23 '05 #3

P: n/a
JRS: In article <c6**************************@posting.google.com >,
dated Tue, 12 Oct 2004 13:17:40, seen in news:comp.lang.javascript,
Robert <rc*******@my-deja.com> posted :
function registerCookie(cookieName,cookieValue) {
var today = new Date()
var expires = new Date()
expires.setTime(today.getTime() + 1000*60*60*24*365)
setCookie(cookieName, cookieValue, expires)
}


function registerCookie(cookieName, cookieValue) {
var D = new Date()
D.setFullYear(D.getFullYear() + 1)
setCookie(cookieName, cookieValue, D)
}

makes more sense.

In the original code, expires = new Date(0) would be better; it's
generally worth spending a character to save determining a date/time
which will not be used.

It seems that in most books the code is not good.

In that context, the final D is used in D.toGMTString() - that format is
undefined in ECMA-262, and in my system does not comply with the
apparent specification for a cookie date string. But the interpretation
of cookie date strings is probably liberal enough, at least for the time
being.

It would have been smarter to follow the US FIPS for cookie dates; that
would have given AIUI all the advantages of ISO 8601 without being
embarrassingly foreign.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.