[英]Disable confirm navigation if page is postback
I have included a script that prompts "confirm navigation" when user makes changes on the form here is the code:我已经包含了一个脚本,当用户在表单上进行更改时提示“确认导航”,这里是代码:
var warning = true;
window.onbeforeunload = function () {
if (warning) {
return "You have made changes on this page that you have not yet confirmed. If you navigate away from this page you will lose your unsaved changes";
}
}
$('claimformmain').submit(function () {
window.onbeforeunload = null;
});
my problem is I have a function that has postback, can I disable the script if page is postback?我的问题是我有一个具有回发的功能,如果页面是回发,我可以禁用脚本吗? thanks
谢谢
You can do something like this.你可以做这样的事情。
Add one hidden field in Your HTML在您的 HTML 中添加一个隐藏字段
<input type="hidden" id="hdnIsPostBack" value="false" />
Write in your code behind写在你的代码后面
if(Page.IsPostBack)
hdnIsPostBack.Value = "true";
else
hdnIsPostBack.Value = "false";
And your Jquery function is go this way.你的 Jquery 函数就是这样。
$( document ).ready(function() {
if( $('#hdnIsPostBack').val() == "true")
{
//Your Function goes here.
}
}
您可以将单击事件附加到您的回发控件,您可以在其中将 window.onbeforeunload 设置为 null。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.