Reply
javascript - setting cookies OnClick
Old 09-27-2004, 07:41 AM javascript - setting cookies OnClick
Junior Talker

Posts: 1
I have been successfully using a cookie redirection script to determine if a visitor had seen the page that day and if so redirect them to another.

This is what I used

/* Copyright http://www.perlscriptsjavascripts.com
Free and commercial Perl and JavaScripts */

// page to go to if cookie exists
go_to = "http://next page.htm";

// number of days cookie lives for
num_days = 1;
function ged(noDays){
var today = new Date();
var expr = new Date(today.getTime() + noDays*24*60*60*1000);
return expr.toGMTString();
}

function readCookie(cookieName){
var start = document.cookie.indexOf(cookieName);
if (start == -1){
document.cookie = "seenit=yes; expires=" + ged(num_days);
} else {
window.location = go_to;
}
}

readCookie("seenit");
// -->
</script>

and it works fine

However I would ideally like to set the cookie when a link was clicked not when the page first loads

I tried an OnClick command along with the banner and link in the body section
but then I got lost.
what do I place in the head section
what do I remove to stop it from setting the cookie onload.

I want to set a cookie when a banner is clicked

and if that cookie is found, go_to new link

I would be grateful if someone could help me

Thanks

Richard

Last edited by 65pbiz : 09-27-2004 at 07:43 AM. Reason: e-mail notification
65pbiz is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Reply     « Reply to javascript - setting cookies OnClick
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12475 seconds with 13 queries