...

View Full Version : :: help with cookies ::



babelfish
08-05-2004, 12:58 PM
Hi peeps :thumbsup:

im after the following:

: check for a cookie to see if this page has been accessed b4
: if yes do nothing
: if no should popup a page & create a cookie to show this process doesnt need doing again..

does that make sense? im not with it today! :confused:

Mr J
08-05-2004, 05:38 PM
How about a "pop once" script


<SCRIPT language=JavaScript>
<!--
cookie_name="poponce"
expDays = 365; // number of days the cookie should last

function get_cookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return get_cookie_val (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}

function get_cookie_val(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function set_cookie (name, value,expires) {
var argv = set_cookie.arguments;
var argc = set_cookie.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 delete_cookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = get_cookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function checkCount() {
var count = get_cookie('poponce');
if (count == null) {
count=1;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
set_cookie('poponce', count, exp);

dothis()
}
}

function dothis(){
var windowprops = "left=50,top=150,width=300,height=200,location=no,toolbar=no,menubar=no,scrollbars=no"; window.open("page.htm", "", windowprops);
}
// -->
</SCRIPT>


<BODY OnLoad="checkCount()">

babelfish
08-06-2004, 09:10 AM
cheers m8e! works a treat!

AaronW
08-06-2004, 09:40 PM
*points* Babel's making popups! :p Haha, just kidding.

I typically use PHP to handly any cookie work, mainly because I've never bothered leanring how to handle JS cookies... Might just study this script ;) Thanks.

babelfish
08-09-2004, 08:59 AM
hmmm dont have php here at work... just lotus domino servers...

i had to not use that popup script fully in the end as so many people have popup blockers here at work! i just use an ammended version of the above to refer to another page now:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum