Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
665 views
in Technique[技术] by (71.8m points)

cookies - How to exclude this exit popup javascript from running on specific urls?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...