...

View Full Version : help with cookie



mex
02-01-2004, 08:33 AM
Can anyone help me out with this script so that it does NOT ask or popup every time the page loads....

<SCRIPT language="JavaScript">
<!--
var yourname= prompt('Do enter your name for a proper welcome :', ' ');
if ( (yourname==' ') || (yourname==null) )
{
yourname="mex";
}
//-->
</SCRIPT>

Pliz make the script as small as possible and also if possible to reset itself after an hour or so as 24 hrs is a bit too long!

Willy Duitt
02-01-2004, 08:02 PM
Try this:

<script type="text/javascript">
<!--//

function doWelcome() {
var dc = document.cookie;
if(dc.length > 0) {
document.getElementById('welcome').innerHTML = 'Welcome back '+ dc;
}

if(dc.length == 0) {
var yourname = prompt('Do enter your name for a proper welcome :', '');
if (yourname == '' || yourname == 'null') {yourname = 'mex';}
else {yourname = yourname;}
document.getElementById('welcome').innerHTML = 'Welcome '+ yourname;
var today = new Date();
today.setTime(today.getTime() + 1*60*60*1000);
var expString = "; expires=" + today.toGMTString();
document.cookie = yourname + expString;
}

}
window.onload = doWelcome;
//-->
</script>
</HEAD>

<BODY>
<span id="welcome"></span>

Change 1 to reflect the number of hours to set the cookie.

....Willy

mex
02-02-2004, 07:20 AM
Thanx so much for the help.:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum