繁体   English   中英

ASP.NET-从页面导航离开时显示弹出窗口,然后单击“确定”转到特定页面

[英]ASP.NET - Show a pop up when navigate away from the page and On click of OK go to a specific page

我在页面上有一个用户控件。 当我尝试离开页面时,我想显示一个确认框(例如,我单击了导航到其他URL的链接)。 在确认框中,我希望能够单击“确定”并单击“取消”来导航到特定页面,以执行预期的操作。

以下代码对我不起作用:

window.onunload = function ()

                {
                    if(confirm('You must make elections for the next plan year (Open Enrollment). Click OK to review that event and submit your elections.'))
                    {
                        alert('OK');  
                        window.location.assign('http://www.google.com');                            return false;
                    }
                }

有想法吗?

我建议您在修改它之前保留onunload函数,如下所示:

var existingUnload = window.onunload;
window.onunload = function ()
{
   if(confirm())
    {
      // your custome logic 
       return false;
     }
   else
   {
     existingUnload();
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM