!!blue Posted March 1, 2004 Posted March 1, 2004 So I found a cookie script that's pretty simple which saves a user's preference for a page. Here's the JS code: >function getCookie(NameOfCookie){ if (document.cookie.length > 0) { begin = document.cookie.indexOf(NameOfCookie+"="); if (begin != -1) { begin += NameOfCookie.length+1; end = document.cookie.indexOf(";", begin); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(begin, end)); } } return null; } function setCookie(NameOfCookie, value, expiredays) { var ExpireDate = new Date(); ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000)); document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString()); } function delCookie (NameOfCookie) { if (getCookie(NameOfCookie)) { document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-03 00:00:01 GMT"; } } function DoTheCookie() { Preference=getCookie('Preference'); if (Preference!=null) { window.location.href="http://exampleaddress.com/"+Preference; } else { window.location.href="http://exampleaddresss.com/index.html"; } } in the HTML page the body tags is like this: ><body onload="preloadImages(); DoTheCookie();"> the preloadImages is another function somewhere else... Then the html link for one page is like so: ><a href="#" onClick="setCookie('Preference','index2.html',365)">flash version</a> so, the cookie does save the users' preference but it keeps reloading the page incessantly instead of only once! I think its the body onLoad function, but I don't know enough! feel free to use the code, I found it online; it just didn't come with a lot of explanation. story of my life. thanks a mil, !!blue Quote
HCSuperStores Posted March 2, 2004 Posted March 2, 2004 I looked at the code. And your right, there's nothing thre to STOP the browser from reloading the URL. It just adds on any preferences it happens to find and still reloads the page. You need something that checks the end of the URL, or looks for the parameters passed, before executing the reload. Does that make sense? Quote
!!blue Posted March 2, 2004 Author Posted March 2, 2004 (edited) that makes sense, but I wouldn't know how to do it It's like my Spanish, I can read it but I can't write it. I'll try to search for another cookie; what if I changed the html page by removing function from the body "onLoad" and did the html link like this: ><a href="index2.html" onClick="setCookie('Preference','index2.html',365)">flash version</a> so the pages link AND the preference is set. but I guess that wouldn't work when the user returns on another visit (?). meh, !!blue Edited March 2, 2004 by !!blue Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.