Alldaron
07-27-2012, 06:53 PM
Is this possible, I see redirect for first time visitor which is also cool, but not what I'm looking for. Thanks.
keyboard
07-27-2012, 11:52 PM
When they first arrive at your site, you need to check whether they already have a cookie set on their browser. If they do; redirect them to a different page or display a div with the newest stuff in it. If they don't, create the cookie...
Which bits would you need help with?
bernie1227
07-28-2012, 09:00 AM
Try:
<html>
<head><title>send cookie</title>
<script type='text/javascript'>
var expdate = new Date();expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365));
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset); if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr)); }
function GetCookie (name) { var arg = name + "="; var alen = arg.length;
var clen = document.cookie.length; var i = 0; while (i < clen) {
var j = i + alen; if (document.cookie.substring(i, j) == arg)
return getCookieVal (j); i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break; } return null; }
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (2 < argc) ? argv[2] : null;
var path = (3 < argc) ? argv[3] : null;
var domain = (4 < argc) ? argv[4] : null;
var secure = (5 < argc) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : ""); }
function DeleteCookie (name,path,domain) {
if (GetCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thur, 01-Jan-70 00:00:01 GMT";
}
}
function set_href_cookie(href_val){
SetCookie('href_location', href_val, expdate, '/', null, false);
document.location.href=href_val;
}
</script>
</head>
<body onbeforeunload="set_href_cookie('href_value')">
<script type='text/javascript'>
cookie_name = GetCookie("href_location");
if(cookie_name){
alert("Cookie found, redirecting to stored cookie.");
document.location.href=cookie_name;
}
</script>
</body>
</html>
The only problem here however, is triggering setting the cookie. At the moment, I am using onbeforeunload to trigger it, so it triggers the cookie before they are about to leave the page (don't ask me how it works), however the only problem with this, is that it will trigger it when they are are about to leave any page on your website, However I have made it so that it overwrites the cookie each time, so that when they leave the page for good, it should read the cookie with the URL of the last page they were on.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.