[英]How Do I Use JavaScript To Prevent A Window From Closing Without The Popup With The “Are You Sure You Want To Leave This Page” Message?
[英]Execute Javascript on Refresh Without the “Are you sure you want to leave the page” Prompt
在某些情况下,当用户刷新页面时,我需要执行几行。
目前,我使用onbeforeunload
事件来执行此操作,如下所示, 但是我正在寻找一种在没有提示的情况下执行此操作的方法。 我只是想让它发生在幕后
该解决方案可以是纯JS(首选),也可以基于jQuery。
//to kill the modal incase refresh or page exit
window.onbeforeunload = closingCode;
function closingCode() {
//bunch of functions here to run before refresh/close
window.location.href = window.location.href.split('#')[0]; //remove leftover hash symbol if it exists
return false;
}
尝试这个 ;)
window.onbeforeunload = function(){ inst.close(); inst.destroy(); window.location.href = window.location.href.split('#')[0]; //remove leftover hash symbol if it exists return; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.