我试图在 html 和 js 中执行此操作,但不刷新或重新加载,只是在关闭时触发。我使用了 onbeforeunload、unload 等函数,但它们不起作用。
sample image
最佳答案
用 jQuery 试试这个:
$(window).bind('beforeunload', function(){
return 'Are you sure you want to leave?';
});
或者使用 JavaScript
window.onbeforeunload = function(){
return 'Are you sure you want to leave?';
};
关于Javascript/Html 关闭窗口事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39270546/