But I want to save two name-value pairs to the cookie. You're s'pose to be able to put (for example):
HKMapWidth=200;HKMapHeight
Main Topics
Browse All TopicsI'm using IE5 and I want to save a cookie, that records what the browser dimensions were when it closed. Then when you open that page, it can remember it. But for some reason it's only saving the first cookie name-value pair. The onLoad and onUnload seem to be working strangley too. Hope you can help! Here's the code:
<html>
<head>
<title>Page Size</title>
<link rel="stylesheet" type="text/css" href="../css/map.css">
<meta name="Author" content="Ben Weeks">
<script language="JavaScript">
<!-- // Hide from incompatible brosers
function getPageSize()
{
alert("boo!");
document.write("<p>" + document.cookie + "</p>");
HKMapWidth = getCookieData('HKMapWidth'
HKMapHeight = getCookieData('HKMapHeight
document.write("<p>HKMapWi
}
function savePageSize()
{
alert("saving cookie!");
// Find the browser dimensions.
var browserWidth = document.body.offsetWidth;
var browserHeight = document.body.offsetHeight
// Set the expirey date one year from now. Must be in GMT format.
var exp = new Date();
var oneYearFromNow = exp.getTime() + (365 * 24 * 60 * 60 * 1000);
exp.setTime(oneYearFromNow
// If cookie already exists it will over-ride the old value, if it doesn't it will create a new cookie.
// NB See p308 in the JavaScript Bible 3rd Edition for more information.
document.cookie = "HKMapWidth=" + browserWidth + ";HKMapHeight=" + browserHeight + ";expires=" + exp.toGMTString();
}
function getCookieData(label)
{
// this function can be found on p311 of the JavaScript Bible 3rd Edition.
// More cookie retrieving functions can be found at:
// http://www.hidaho.com/cook
label = label + "="; // Assume cookie is in the format of cookieName=cookieValue, i.e. no spaces.
var labelLen = label.length;
var cookieLen = document.cookie.length;
var i = 0;
while (i < cookieLen)
{
var j = i + labelLen;
if (document.cookie.substring
{
strEnd = document.cookie.indexOf(";
if (strEnd == -1)
{
strEnd = document.cookie.length;
}
return unescape(document.cookie.s
}
i++
}
return "";
}
// -->
</script>
<body onLoad="getPageSize()" onUnload="savePageSize()">
</body>
</html>
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
function setCookie (name,value,expires,path,t
var theCookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((theDomain) ? "; domain=" + theDomain : "") +
((secure) ? "; secure" : "");
document.cookie = theCookie;
}
setCookie("HKMapWidth", "200")
setCookie("HKMapHeight", "400")
(add the third parameter yourself with your time, when it should expire...)
regards,
CJ
Still seems to do the same, see www.webtechy.co.uk/pagesiz
And then look for the cookie www.webtechy.co.uk in your internet temporary files location (IE).
i.e. it's just saving:
HKMapWidth
1124
www.webtechy.co.uk/
0
2763775744
29482136
738584544
29408711
*
in the cookie.
OK, I've now got it working - thanks! One last thing - if I place this on a server that may also use cookies, will my code affect any other cookies that they may have? See:
www.webtechy.co.uk/openpag
for how this is actually being used.
Thanks again!
Business Accounts
Answer for Membership
by: CJ_SPosted on 2001-04-05 at 04:35:51ID: 5989156
ou can use the following function if you'd like
heDomain,s ecure) {
function setCookie (name,value,expires,path,t
var theCookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((theDomain) ? "; domain=" + theDomain : "") +
((secure) ? "; secure" : "");
document.cookie = theCookie;
}