We have a custom code on our website that displays a pop-up form when users are leaving. But it shows on every webpage. I can't figure out the correct way to exclude certain urls. Can you help?
//Exit Popup Cookie
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;
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
// Exit Popup Logic
var visited = readCookie('visited');
var opened = false;
jQuery(document).ready(function() {
setTimeout(function () {
if ( !visited || visited !== "true") { //is there a cookie?
jQuery(document).on('mouseleave', leaveFromTop);
function leaveFromTop(e){
if( e.clientY < 0 && !opened ){ //check if popup fired in current window
jQuery('#exitModal1').modal('show');
jQuery('#contactModal').modal('hide');
createCookie('visited', "true", 1);
opened = true;
}
}
}
}, 5000);
console.log(visited);
});
question from:
https://stackoverflow.com/questions/66046926/how-to-exclude-this-exit-popup-javascript-from-running-on-specific-urls 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…