0

I've got this code that shows an annoying ext intent overlay when going to the back button, but I don't want it to show up if a specific cookie exists. This is the cookie my exit button makes.

JavaScript:

function dontshow(){       
    days=30;
    myDate = new Date();
    myDate.setTime(myDate.getTime()+(days*24*60*60*1000));    
    document.cookie = 'dontshow=OK; expires=' + myDate.toGMTString();     
}

This is the code which shows my exit intent overlay.

JavaScript:

$(document).ready(function() {
    canRun = false;
    waitPeriod = 1000;// waiting time
    setTimeout(function() { canRun = true; }, waitPeriod);     

    $(document).on("mouseleave", function (event) {
        if (!canRun) {
            return false;
        }
        if (event.pageY < 0) {
            $(".leavemodal").fadeIn(600);
        }
    });
});

I want to make an if and else statement saying: If the cookie "dontshow" exists, don't run the code for my exit intent overlay. I've tried some stuff but it's not working. Does anyone have any ideas on how to get it to work.

2
  • if (document.cookie.indexOf('dontshow=OK') > -1) would this not work? Commented Sep 7, 2016 at 8:51
  • it works, thanks man Commented Sep 7, 2016 at 9:16

1 Answer 1

0

You have to check if there substring in cookie string by indexOf method.

if (document.cookie.indexOf("dontshow=OK") != -1) ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.