Reputation: 117
I'm trying to modify some code to direct users to a "create an account" squeeze page on their first visit. I think I'm close, but I need a little help. Any advise on where I went wrong?
<script type="text/javascript">
$(document).ready(function() {
// check cookie
var visited = $.cookie("visited")
if (visited == null) {
window.location = "content/content-article.asp?ArticleID=4998"
$.cookie('visited', 'yes');
alert($.cookie("visited"));
}
// set cookie
$.cookie('visited', 'yes', { expires: 10,000, path: '/' });
});
Upvotes: 2
Views: 4473
Reputation: 117
OK - I kept digging and found a different script that worked. Here it is in case someone else is trying to do the same thing:
<script type="text/javascript">
function redirect(){
var thecookie = readCookie('doRedirect');
if(!thecookie){window.location = 'http://yournetwork.com/splash';
}}function createCookie(name,value,days){if (days){var date = new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires = "; expires="+date.toGMTString();}else var expires = "";document.cookie = name+"="+value+expires+"; path=/";}function readCookie(name){var nameEQ = name + "=";var ca = document.cookie.split(';');for(var i=0;i < ca.length;i++){var c = ca[i];while (c.charAt(0)==' ') c = c.substring(1,c.length);if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);}return null;}window.onload = function(){redirect();createCookie('doRedirect','true','999');}
Upvotes: 3
Reputation: 895
Try this:
$(document).ready(function() {
// check cookie
var visited = $.cookie("visited")
// set cookie
$.cookie('visited', 'yes', { expires: 10,000, path: '/' });
if (visited == null) {
$.cookie('visited', 'yes');
alert($.cookie("visited"));
window.location = "content/content-article.asp?ArticleID=4998"
}
});
Change the location to another site AFTER executing your code
Upvotes: 0