I need to check if a cookie exists when the user lands on a page and if the cookie does not exist I need to popup an alert and then redirect to another page.
if( $.cookie('cookiename') == null ) {
alert("OH NOES U NO HAS COOKIE");
window.location.replace('http://url');
}
if( document.cookie.indexOf("cookiename=") < 0) {
alert("Cookie not found, redirecting you.");
location.href = "newpage.html";
}
Be careful not to use a cookie name that may be the end of another cookie name. If this is likely, you'll need to do a full cookie read, or use PHP instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With