gpt4 book ai didi

javascript - 当用户关闭任何特定选项卡时如何显示提示? (这是关于不适用于所有浏览器的单个选项卡)

转载 作者:行者123 更新时间:2023-11-30 17:40:16 25 4
gpt4 key购买 nike

我正在从事一个项目,我需要在其中进行一些定制开发。其中之一是当用户关闭特定选项卡时我必须显示一个弹出窗口。我已经尝试了一些解决方案,但它无法正常工作。它要么在整个浏览器上工作,要么根本不工作。那么当用户关闭任何特定选项卡时,我如何实现提示。

我试过的解决方案是 Solution i tried

最佳答案

var validNavigation = false;

function wireUpEvents() {
/**
* For a list of events that triggers onbeforeunload on IE
* check http://msdn.microsoft.com/en-us/library/ms536907(VS.85).aspx
*
* onbeforeunload for IE and chrome
* check http://stackoverflow.com/questions/1802930/setting-onbeforeunload-on-body-element-in-chrome-and-ie-using-jquery
*/
var dont_confirm_leave = 0; //set dont_confirm_leave to 1 when you want the user to be able to leave withou confirmation
var leave_message = 'You sure you want to leave?'
function goodbye(e) {
if (!validNavigation) {
if (dont_confirm_leave!==1) {
if(!e) e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = leave_message;
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
//return works for Chrome and Safari
return leave_message;
}
}
}
window.onbeforeunload=goodbye;

// Attach the event keypress to exclude the F5 refresh
$(document).bind('keypress', function(e) {
if (e.keyCode == 116){
validNavigation = true;
}
});

// Attach the event click for all links in the page
$("a").bind("click", function() {
validNavigation = true;
});

// Attach the event submit for all forms in the page
$("form").bind("submit", function() {
validNavigation = true;
});

// Attach the event click for all inputs in the page
$("input[type=submit]").bind("click", function() {
validNavigation = true;
});

}

// Wire up the events as soon as the DOM tree is ready
$(document).ready(function() {
wireUpEvents();
});

关于javascript - 当用户关闭任何特定选项卡时如何显示提示? (这是关于不适用于所有浏览器的单个选项卡),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21228279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com