【发布时间】:2018-11-13 19:33:35
【问题描述】:
当用户使用以下代码单击浏览器的刷新或关闭按钮时,我让浏览器显示确认模式:
window.onbeforeunload = confirmCloseOrRefresh;
function confirmCloseOrRefresh() {
var confirmMessage = confirm('Are you sure to exit?');
return confirmMessage;
}
现在,我的页面上有一个自定义刷新按钮,我想手动刷新页面而不显示确认模式。
我试过了:
onRefreshButtonClick(event) {
event.preventDefault();
window.location.reload();
return true;
}
仍然显示确认模式。有什么方法可以取消/覆盖此函数中的确认模式?
【问题讨论】:
-
window.onbeforeunload = null;?
标签: javascript