OZONE Asylum
Forums
DHTML/Javascript
JavaScript Cookie Redirect
This page's ID:
30213
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Hi kuckus, thank you for your help. Modified the script placed on page [b]A[/b] that looks like this: [code] <script> <!-- num_days = 5; function ged(noDays){ var today = new Date(); var expr = new Date(today.getTime() + noDays*24*60*60*1000); return expr.toGMTString(); } go_to = "index2.php"; num_days = 5; function readCookie(cookieName){ var start = document.cookie.indexOf(cookieName); if (start == -1){ document.cookie = "bin" + ged(num_days); } else { window.location = go_to; } } readCookie("bin"); // --> </script> [/code] No more errors but unfortunately it sets another cookie with no name which messes everything up, I have no skills to edit the script myself and I'm sorry if I sound like a broken record :(. Is there another solution for the script to just read the cookie and if its there to redirect to a given page ? After/If the first script writes the cookie . I thank anyone who helps me make this script ! On the first page I had another script that placed a cookie based on a PHP command: [code] <script language="JavaScript"> function setCookie(name, value, expires) { if (!expires) expires = new Date(); document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/"; } var expdate = new Date (); expdate.setTime(expdate.getTime() + 999999999); setCookie("<?php echo $sold;?>","true",expdate); </script> <script> [/code] And in the config.php file I have: [code] $sold = "no"; [/code] On the same page below the first script is: [code] <script> <!-- go_to = "index3.php"; num_days = 5; function readCookie(cookieName){ var start = document.cookie.indexOf(cookieName); if (start == -1){ document.cookie = "yes" + ged(num_days); } else { window.location = go_to; } } readCookie("yes"); // --> </script> [/code] After I edit the config.php file with the "yes" value page [b]A[/b] redirects to a completely different page ( for the people who don't have the first cookie set on page [b]B[/b] ...so, I modified both scripts with your suggestion [b]kuckus[/b], and it somehow writes this cookie: [img]http://img88.imageshack.us/img88/8196/12163060qu0.jpg[/img] This cookie is the 'yes' or 'no' cookie: [img]http://img245.imageshack.us/img245/343/50661006yb5.jpg[/img] Any help in making this simple script SIMPLE would be great, without [b]num_days[/b] or [b]ged[/b] functions. The problem is the script that reads the cookie, not the one that sets it. Simple means: Read the cookie, if its not set/there do nothing, if its there redirect/go to another page... On another note everything works fine with the first version of the script that gave those errors. IE 7 doesn't display "Done. But with errors on page" and on Firefox it works fine also, I know people don't use IE 6 that much but I don't like IE 7 at all and I want this script to work w/o any errors. I'm sure there are lots of people who might find this script usefull , I found this forum browsing on google for help :) Thanks for reading. [small](Edited by [url=http://www.ozoneasylum.com/user/6754]cyanide[/url] on 04-22-2008 01:34)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »