[英]Exit Popup Redirect but only execute on exit not on clicking any other html redirect button on page
我正在使用此代碼
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);
但它也可以通過單擊頁面上的任何html重定向按鈕來執行。.我希望僅當有人關閉瀏覽器並且它應該支持所有瀏覽器時執行它。
我只需要在網站的一個鏈接處添加ID,ID怎么辦? 我的意思是我正在使用此代碼進行重定向
<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>
所以我想退出功能不為此執行..所以如何集成這個
我尚未測試過,但您應該可以將'click'事件附加到頁面上的每個鏈接上,這應該設置一個全局變量,例如
linkClicked = true;
然后,您可以在卸載事件中檢查該變量
if (!linkClicked) // variable is false so they must not have clicked on a link
{
// Some annoying message here
}
免責聲明:這幾乎是偽代碼,它不是復制+粘貼解決方案。
window.onbeforeunload
不區分鏈接,后退/前進按鈕,退出按鈕或其他任何東西。 如果在離開頁面時觸發,則無論如何離開頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.