Got a quick (cookie) question.
I looked on the internet for some cookie scripts (redirect ones), but unfortunately haven’t been too lucky with these.
What I want to do is the following:
When the cookie is not found it goes to my main page, for example:
“www.anynamehere.com”
On the main page I can select where I want to go -
‘Contacts’, ‘News’, ‘Forums’ and so on. The main page has a drop down list with these options, each option has it’s own link.
When I click on ‘continue’ and go to the specific link (ex. www.anynamehere.com/contacts.html) it should remember my selection, so next time I log into www.anynamehere.com it’s automatically will take me to contacts.html. I will not see the main page anymore.
Now, if from the contacts page I select ‘News’ and go to www.anynamehere.com/news.html it has to remember that link as well. So if I close my browser and then reopen it, it should take me to www.anyname.com/news.html.
I hope that makes sense.
If anyone can give me any pointers I would greatly appreciate it. Maybe there is a script like that available online, I just wasn’t lucky enough to find one.
you may have to stick with php, and use .htaccess to rewrite your urls to accomadate the .html extension, or configure apache somehow to parse php inside of an html page
Here’s a very rough prototype I adapted from my book “JavaScript: Just the Basics.” When you load Test.html, it looks for the FormerLocation cookie. If it finds it, it automatically navigates to that page. Test.html has a link to Test01.html. If you go to Test01.html, the script saves the current URL in the FormerLocation cookie. It saves the cookie for 1 hour, but you can change the lifetime to anything you want.
Test.html:
<!DOCTYPE html>
<html>
<head>
<title>Home Page</title>
<script>
var FormerLocation = getFormerLocationCookie ();
if (FormerLocation)
window.location = FormerLocation;
function getFormerLocationCookie ()
{
/* get all cookies: */
var allCookies = document.cookie;
if (allCookies === "")
return null;
/* break up all-cookie string into an array: */
var cookieList = allCookies.split ("; ");
/* search through the array for the FormerLocation cookie: */
for (var i = 0; i < cookieList.length; ++i)
{
var cookie = cookieList[i];
var idx = cookie.indexOf ("=");
/* extract cookie name: */
var name = cookie.substring (0, idx);
if (name === "FormerLocation")
{
/* correct cookie found: extract, decode, & return cookie value: */
var value = cookie.substring (idx+1);
return decodeURIComponent (value);
}
}
return null;
}
</script>
</head>
<body>
<h2>Home Page</h2>
<a href="Test01.html">Go to Test01</a>
</body>
</html>
Test01.html:
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Tester Page</title>
<script>
/* for IE only: */
var date = new Date();
date.setHours (date.getHours()+1);
document.cookie = "FormerLocation=" + encodeURIComponent (window.location) + "; max-age=3600; expires=" + date.toGMTString();
</script>
</head>
<body>
<h2>JavaScript Tester Page</h2>
</body>
</html>