Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 短jquery退出弹出脚本需要修改_Javascript_Php_Jquery_Html_Ajax - Fatal编程技术网

Javascript 短jquery退出弹出脚本需要修改

Javascript 短jquery退出弹出脚本需要修改,javascript,php,jquery,html,ajax,Javascript,Php,Jquery,Html,Ajax,下面是我在互联网上找到的一个退出弹出窗口的脚本 这个脚本非常好用。它会在退出弹出窗口显示离开/停留页面按钮的同时更改页面 然而,我希望让它连续工作两次,例如,您在index.php上 按exit,当前页面AJAX将加载并覆盖页面_exit.php(技术上仍在index.php上) 用户决定留在页面上阅读新的覆盖div 再次尝试关闭页面后,但这次它使用page_exit_2.php重新加载div 目前,它将继续尝试加载page_exit.php,我不确定如何告诉它在第一次尝试退出后加载page_e

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

这个脚本非常好用。它会在退出弹出窗口显示离开/停留页面按钮的同时更改页面

然而,我希望让它连续工作两次,例如,您在index.php上

按exit,当前页面AJAX将加载并覆盖页面_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

哎呀!这种唠叨不是反社会吗?如果所有网站都像这样工作,我们会让网站成为一个非常令人沮丧的地方。好吧,查看第二个退出页面的唯一方法是单击第一个页面的“停留在页面上”,然后决定再次退出。你的想法是对的,就个人而言,我不喜欢它们,但这是针对我的一个新项目:)使用会话或变量来存储状态,如果退出一次,则将值设置为1或true。退出页面page_exit.php | | page_exit_2.php?但正如哈弗个人所说,他根本不喜欢这种方法。谢谢你的评论。我尝试在发送第一个弹出窗口后更改变量。但之后,javascript似乎不再被读取。我不太懂javascript,所以我应该在上面的脚本中添加代码到哪里?非常感谢你的帮助。我也不喜欢这些,但这是一个只有少数人会看到的项目。我尝试在window.onbeforeunload=function(){处更改ExitPopURL,但没有效果。似乎只调用了一次函数。你知道吗?