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
Hello everybody. I just joined this forum today and I must say I'm glad I did, helped me in making a cookie redirect script. I though to share this one because believe me I've searched everywhere... no skills = no power I suppose :). This is what I wanted the script to do: User enters page [b]A[/b] and moves on to page [b]B[/b], if he tries to access page [b]A[/b] again to be redirected to page [b]C[/b]. I tried at first with a PHP cookie redirect but I didn't like the fact that I needed to use the Refresh button for the cookie to load... I don't know much PHP coding so... Script placed in page [b]B[/b]: [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("NameOFtheCOOKIE","true",expdate); </script> [/code] Script placed on page [b]A[/b]: [code] <script> <!-- go_to = "http://www.site.com/pageC.html"; function readCookie(cookieName){ var start = document.cookie.indexOf(cookieName); if (start == -1){ document.cookie = "NameOFtheCOOKIE" + ged(num_days); } else { window.location = go_to; } } readCookie("NameOFtheCOOKIE"); // --> </script> [/code] This was done by copying the source from another script...if there's a way to make it simpler I'd really appreciate the effort. It gives some errors on this line: document.cookie = "NameOFtheCOOKIE" + ged(num_days); :( Thanks. Original script: [code] <script> <!-- go_to = "http://www.site.com"; num_days = 60; 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> [/code] [small](Edited by [url=http://www.ozoneasylum.com/user/6754]cyanide[/url] on 04-19-2008 08:11)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »