简体   繁体   English

退出弹出式重定向,但仅在退出时执行,而不是单击页面上的任何其他html重定向按钮

[英]Exit Popup Redirect but only execute on exit not on clicking any other html redirect button on page

l am using this code 我正在使用此代码

var exitPop = false;
var nonFire = false;
window.onbeforeunload = function () {
    if(!exitPop){
        exitPop=true;
        return 'Wait! YOU ARE TODAYS WINNER!';
    }
};

setInterval(function(){
    if(exitPop && !nonFire){
        nonFire = true;
        window.location.href = 'http://google.com';
    }
}, 200);

but its also execute on clicking any html redirect button on page.. i want it execute only if someone close browser and it should support all browsers. 但它也可以通过单击页面上的任何html重定向按钮来执行。.我希望仅当有人关闭浏览器并且它应该支持所有浏览器时执行它。

i need to add this at only one link in my site how can id do? 我只需要在网站的一个链接处添加ID,ID怎么办? i mean i am using this code for redirect 我的意思是我正在使用此代码进行重定向

<script type="text/javascript"> 

window.fbAsyncInit = function() {
    FB.Event.subscribe('comment.create',
    function (response) {
        window.location = "http://domain.com";
    });
    FB.Event.subscribe('comments.remove',
    function (response) {
        window.location = "http://domain.com";
    });   
};

(function() {
    var e = document.createElement('script');
    e.async = true;
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
}());
//]]>
</script>

so i want exit function do not execute for this.. so how do integrate this 所以我想退出功能不为此执行..所以如何集成这个

I haven't tested it but you should be able to attach a 'click' event to every link on the page, which should set a global variable such as 我尚未测试过,但您应该可以将'click'事件附加到页面上的每个链接上,这应该设置一个全局变量,例如

linkClicked = true;

You can then check that variable in the unload event 然后,您可以在卸载事件中检查该变量

if (!linkClicked) // variable is false so they must not have clicked on a link
{
    // Some annoying message here
}

Disclaimer: this is pretty much pseudo code, it's not a copy+paste solution. 免责声明:这几乎是伪代码,它不是复制+粘贴解决方案。

window.onbeforeunload does not distinguish between links, back/forward buttons, exit buttons or anything else. window.onbeforeunload不区分链接,后退/前进按钮,退出按钮或其他任何东西。 If fires when you leave the page, regardless of how you leave the page. 如果在离开页面时触发,则无论如何离开页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM