【发布时间】:2018-04-20 07:46:21
【问题描述】:
我使用 JavaScript 函数 beforeunload 在加载应用程序期间显示模式。 我的母版页中的代码:
<script>
window.addEventListener("beforeunload", function (e) {
var modal = document.createElement("div");
modal.className = "modal-backdrop fade in"
modal.innerHTML = ' ';
var loader = document.createElement("div");
loader.className = "loader"
loader.innerHTML = '<i class="glyphicon glyphicon-hourglass"></i><br/><br/>Veuillez patienter...<br/>';
document.body.appendChild(modal);
document.body.appendChild(loader);
return null;
});
</script>
除了生成excel文件的按钮事件外,它运行良好。未检测到加载结束,因此模态不会关闭。
有关信息,我给出了按钮事件的 c# 代码的结尾:
Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
我尝试在我的按钮事件中调用此函数,但它不起作用:
function stopNavigate() {
window.onbeforeunload = null;
}
如何只禁用此按钮的 beforeunload?
【问题讨论】:
-
当用户选择关闭标签/窗口时,为什么要添加沙漏?
-
我在浏览器加载时添加沙漏,而不是在用户选择关闭窗口时添加一个沙漏
-
???...
beforeunload在关闭时触发,而不是加载,因此您的问题毫无意义。
标签: javascript c# asp.net webforms onbeforeunload