[英]Prevent page refresh in asp.net but not postback by using javascript or asp.net
我使用下面提到的JavaScript代碼來防止頁面重新加載,但是當我重定向頁面時,它也會執行此代碼。 我該如何預防呢? 我只想在頁面刷新時執行此代碼。
$(document).ready(function () {
$(window).bind('beforeunload', function () {
return 'Are you sure you want to reload or leave this page? All progress will be lost.';
});
});
謝謝
您可以將isDirty
變量添加到頁面。
true
false
isDirty === true
時返回消息 您可以覆蓋回發函數並在其中取消綁定beforeunload事件:
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
$(window).unbind('beforeunload');
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.