Javascript ASP.NET-当导航离开页面并单击“确定”转到特定页面时,显示弹出窗口
我在页面上有一个用户控件。当我试图离开页面时,我想显示一个确认框(例如,我单击了一个导航到不同URL的链接)。在“确认”框中,我希望能够在单击“确定”和单击“取消”时导航到特定页面并执行预期操作 以下代码不适用于我:Javascript ASP.NET-当导航离开页面并单击“确定”转到特定页面时,显示弹出窗口,javascript,jquery,asp.net,Javascript,Jquery,Asp.net,我在页面上有一个用户控件。当我试图离开页面时,我想显示一个确认框(例如,我单击了一个导航到不同URL的链接)。在“确认”框中,我希望能够在单击“确定”和单击“取消”时导航到特定页面并执行预期操作 以下代码不适用于我: window.onunload = function () { if(confirm('You must make elections for the next plan year (Open Enrollm
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();
}
}您在哪个页面执行上述代码?