簡體   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