Reputation: 163
Forgive me, my jQuery/javascript knowledge is still in learning mode.
I have an exit-intent modal that pops up on my page. I'm using the jQuery cookie plugin to make sure that it doesn't come up again for a while. This is all working correctly, with one exception. If it's triggered on a page, it will trigger again on that same page if you don't navigate away. So someone closes the modal, then scrolls around the page, then has the modal come up again if they mouse away.
My question is, how can I remove that function, or alter it, once it's triggered one time? I know that it would only apply on that one page, but I'm hopeful the cookie will take care of it after they navigate away.
Thoughts? Here's my code so far.
// Exit intent
function addEvent(obj, evt, fn) {
if (obj.addEventListener) {
obj.addEventListener(evt, fn, false);
}
else if (obj.attachEvent) {
obj.attachEvent("on" + evt, fn);
}
}
// Cookie Expires every 5 Days
$(document).ready(function() {
var visited = $.cookie('visited');
if (visited == 'yes') {
return false;
} else {
addEvent(document, 'mouseout', function(evt) {
if (evt.toElement == null && evt.relatedTarget == null ) {
$('#modal').fadeIn();
$('.modalmask').fadeIn();
}
});
}
$.cookie('visited', 'yes', { expires: 5, path: '/' });
});
// Closing the Popup Box
$('.close_modal, .modalmask').click(function() {
$('#modal').fadeOut();
$('.modalmask').fadeOut();
});
Upvotes: 0
Views: 295