Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 关闭选项卡前的确认框,而不是页面重新加载时的确认框_Javascript_Asp.net_Webforms - Fatal编程技术网

Javascript 关闭选项卡前的确认框,而不是页面重新加载时的确认框

Javascript 关闭选项卡前的确认框,而不是页面重新加载时的确认框,javascript,asp.net,webforms,Javascript,Asp.net,Webforms,我的客户端要求在关闭web应用程序的浏览器选项卡时发出警报消息。可以使用JavaScriptonunload或onbeforeunload事件来完成 但在我的应用程序中有很多下拉框,选择一些下拉框,页面需要重新加载。在此重新加载过程中,每次启动onunload或onbeforeunload并显示警报消息时。我想在重新加载页面上停止触发此onnload或onbeforeuload事件,但在浏览器选项卡关闭时显示警报消息。如果URL中有任何更改,这将非常有用。但是我的URL没有改变 我知道这种情况没

我的客户端要求在关闭web应用程序的浏览器选项卡时发出警报消息。可以使用JavaScript
onunload
onbeforeunload
事件来完成

但在我的应用程序中有很多下拉框,选择一些下拉框,页面需要重新加载。在此重新加载过程中,每次启动
onunload
onbeforeunload
并显示警报消息时。我想在重新加载页面上停止触发此
onnload
onbeforeuload
事件,但在浏览器选项卡关闭时显示警报消息。如果URL中有任何更改,这将非常有用。但是我的URL没有改变

我知道这种情况没有直接的JavaScript事件支持。有人能提出替代方案吗?

更新:

<script language="JavaScript1.2" type="text/javascript">  

    var g_isPostBack = false;        
    function windowOnBeforeUnload()
    {        
        if ( g_isPostBack == true )
        return; // Let the page unload

        if ( window.event )
        window.event.returnValue = 'Are you sure?'; // IE
        else
        return 'Are you sure?'; // FX
     }
    window.onbeforeunload = windowOnBeforeUnload;    

</script>
protected void Page_Load(object sender, EventArgs e)
        {             
          this.ClientScript.RegisterOnSubmitStatement(this.GetType(), "OnSubmitScript", "g_isPostBack = true;");

        }

如果这是您的要求,请尝试以下代码并更新我们

<script type="text/javascript">
    var new_var = true;
    window.onbeforeunload = function () {
        if (new_var) {
            return "you have unsaved changes, if you leave they will be lost"
        }
    }
    function unhook() {
        new_var = false;
    }
</script>

var new_var=true;
window.onbeforeunload=函数(){
如果(新变量){
return“您有未保存的更改,如果您离开,这些更改将丢失”
}
}
函数unhook(){
new_var=false;
}

遇到同样的问题请尝试此脚本

  <script language="JavaScript" type="text/javascript">
        window.onbeforeunload = confirmExit;
        function confirmExit() {
            return "You are about to exit the system before freezing your declaration! If you leave now and never return to freeze your declaration; then they will not go into effect and you may lose tax deduction, Are you sure you want to leave now?";
        }
        $(function() {
            $("a").click(function() {
                window.onbeforeunload = null;
            });
            $("input").click(function() {
                window.onbeforeunload = null;
            });
        });
    </script>

window.onbeforeunload=确认退出;
函数confirmExit(){
return“您将在冻结您的申报之前退出系统!如果您现在离开并且从未回来冻结您的申报;那么这些申报将不会生效,您可能会失去税收扣减,您确定要现在离开吗?”;
}
$(函数(){
$(“a”)。单击(函数(){
window.onbeforeunload=null;
});
$(“输入”)。单击(函数(){
window.onbeforeunload=null;
});
});

我建议您使用Ajax,这将帮助您在不重新加载/刷新整个页面的情况下更新/选择任何下拉列表。这是一个ERP解决方案,并且已经开发出来了。因此,将每个页面中的每一篇文章都改回Ajax调用并不容易(你能分享一下代码吗,这样我们就可以试着找出答案了。我只需要在用户点击浏览器的选项卡Xclsoe按钮时显示警报消息。
window.onbeforeuload=function(){return“你有未保存的更改,如果你离开,它们将丢失”;}
你的代码将始终显示警报消息(因为它总是真的)在关闭和重新加载选项卡时。是否仅在关闭时使用?