短jquery退出弹出脚本需要以某种方式修改

时间:2014-01-19 11:18:11

标签: javascript php jquery html ajax

下面是我在互联网上找到的退出弹出窗口的脚本。

此脚本完美无缺。它会在退出弹出窗口显示时使用Leave / Stay on page按钮同时更改页面。

但是 - 我希望连续两次工作,例如,你在index.php上。

你按退出并且当前页面AJAX加载并覆盖page_exit.php(技术上仍然在index.php上)

用户决定留在页面上并阅读新的重叠div。

尝试再次关闭页面后,但这次使用page_exit_2.php重新加载div。

目前它将继续尝试加载page_exit.php,我不确定如何告诉它在第一次尝试退出后加载page_exit_2.php。

谢谢。

var ExitPopURL = 'page_exit.php'; //This is the URL where your 'exit page' is located.

var AlertBox = "*****************************************************\n\nWait! Stop! Don't Go!\n\nBefore leaving, we have a special offer for you\n\nClick Sty On Page Now\n\n*****************************************************"; // This is what the alert() pop up verbage says.


window.onload = function(){
    // this is where we start our journey...
    createExitPop();
}// end function onunload

function getChildren(n, skipMe){
    var r = [];
    var elem = null;
    for ( ; n; n = n.nextSibling ) 
       if ( n.nodeType == 1 && n != skipMe)
          r.push( n );        
    return r;
};

function getSiblings(n) {
    return getChildren(n.parentNode.firstChild, n);
}


function ajaxGET(divId, page, effect) 
{ 
     var xmlHttp; 
     try 
    { 
         // Firefox, Opera 8.0+, Safari 
         xmlHttp=new XMLHttpRequest(); 
    } 
     catch(e)   
    { 
         // Internet Explorer 
         try 
         { 
              xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
         } 
         catch(e)   
          { 
               try 
               { 
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
               } 
               catch(e)   
             {      
                    alert("Your browser does not support AJAX!"); 
                  return false; 
             } 
         } 
     } 

    xmlHttp.onreadystatechange=function() 
     { 
         if(xmlHttp.readyState==4) 
          { 
               if(effect == 'collapse') { document.getElementById(divId).style.display='none'; } 
               else                     { document.getElementById(divId).innerHTML=xmlHttp.responseText; } 
         } 
    } 
     xmlHttp.open("GET",page,true); 
    xmlHttp.send(null); 
}

function createExitPop()
{
    var theBody = document.getElementsByTagName('body')[0]; 
    var newdiv = document.createElement('div');
    newdiv.setAttribute('id','ExitDiv');
    theBody.setAttribute('id','body');
    newdiv.setAttribute('style', 'width: 100%; height: 100%;');

        // put div on page
        theBody.appendChild(newdiv);

        //add exit pop to page (contents are from your exit.php(or whatever you named it) page)
        document.getElementById('ExitDiv').value = ajaxGET('ExitDiv', ExitPopURL);

    // style exit pop to resemble its own page
    document.getElementById('ExitDiv').style.display = "none"; 
    document.getElementById('ExitDiv').style.top = '0px'; 
    document.getElementById('ExitDiv').style.left = '0px'; 
    document.getElementById('ExitDiv').style.position = 'relative'; 
    //document.getElementById('ExitDiv').style.backgroundColor = '#FFFFFF';
    document.getElementById('ExitDiv').style.zIndex = 9999;

}// end createExitPop

isExit = true;

function ExitPop(isExit) {
        if(isExit != false) {
            isExit=false;
            isPop = true;

            var bodyTag = document.getElementById? document.getElementsByTagName("BODY")[0] : document.body;

            // add id="body" so that it can be referenced.
            bodyTag.setAttribute("id", "body");



            //replace body text with exit pop
            //bodyTag.innerHTML = document.getElementById('ExitDiv').innerHTML;
            document.getElementById('ExitDiv').style.display = "block"; 

            var oldContent = getSiblings(document.getElementById('ExitDiv'));
            for(i in oldContent ){
                 oldContent[i].style.display = "none";
            }

            return AlertBox;
        } // end if
    }// end function

window.onbeforeunload = function(){

        // Lay down an exit pop!!
        return ExitPop(isExit);

}// end function onunload

0 个答案:

没有答案