Re: cookie question

by "Phil Babcock" <pbabcock(at)bgsgroup.com>

 Date:  Wed, 17 May 2000 13:26:30 -0400
 To:  whirrett(at)netins.net,
"hwg-techniques(at)hwg.org" <hwg-techniques(at)hwg.org>
 References:  lisa
  todo: View Thread, Original
*********** REPLY SEPARATOR  ***********

Lisa Whirrett wrote:

>Can someone tell me where I can find a script that will write a cookie
when
>someone visits index.html so that on subsequent visits they will be
>immediately directed to index2.html?  We use a splash page that we'd like
>visitors to see just once or maybe give them a checkbox option of not
seeing
>it again....
>
>Thanks,
>Lisa
>www.justlisa.com

*********** END REPLY SEPARATOR  ***********

Here ya go:
<!--index.html-->
<html>
<head>
<script LANGUAGE="JavaScript">

<!--cloak engaged

function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function set_loaded(value) {
var expdate = new Date ();
expdate.setTime (expdate.getTime() + (48 * 60 * 60 * 1000 * 31));
var cookievalue = value
SetCookie ("beenhere", cookievalue, expdate);
}

function docookiecheck(){

if (document.cookie.indexOf("beenhere") == -1) {
set_loaded('true');
}
else {
location.href="index2.html"
}
}

// End -->
</script>
</head>
<body bgcolor="#FFFFFF" marginwidth="0" marginheight="0" leftmargin="0"
topmargin="0" onload="docookiecheck()">
<!-- rest of main content -->
</body></html>

Just move the function call to docookiecheck() to wherever you like.  Using
it in onload will mean that they will still see the entire contents of
index.html (however briefly) before being redirected to index2.html.
Alternatively you could do something like:

<body bgcolor="#FFFFFF" marginwidth="0" marginheight="0" leftmargin="0"
topmargin="0">
<script LANGUAGE="JavaScript">

docookiecheck();

</script>
<!-- rest of main content -->
</body></html>

...which would call it immediately - instead of waiting for the page to
load.

Of course I havent tested this out, but it seems sound.

hth,


Phil Babcock
Lead Web Designer
BGS Group Inc.

HWG hwg-techniques mailing list archives, maintained by Webmasters @ IWA

This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.