我的 ASP.NET 应用程序 (VB) 中有一个页面依赖于实时的第 3 方服务,如果发现该服务已关闭,我将使用 jQuery 显示覆盖层。我一直对应用程序中的其他警告使用相同的方法 - 与此不同的是,它需要在用户单击警告弹出窗口上的按钮以删除覆盖层后进行重定向。我尝试了许多不同的方法,但在所有情况下,重定向都是在覆盖警告可见之前发生的。我明白为什么,我只是找不到解决方案来解决它。非常感谢任何帮助!我正在使用以下代码:
jQuery
function warn_redirect(msg, title, nextpage) {
// show modal div
//alert(obj.id);
$("html").css("overflow", "hidden");
$("body").append("<div id='popup_overlay'></div><div id='popup_window'></div>");
$("#popup_overlay").addClass("popup_overlayBG");
$("#popup_overlay").fadeIn("slow");
// build warning box
$("#popup_window").append("<h1>" + title + "</h1>");
$("#popup_window").append("<p id='popup_message'><center>" + msg + "</center></p>");
$("#popup_window").append("<div class='buttons'><center><button id='continue' class='positive' type='submit'>OK</button></center></div>");
// attach action to button
$("#continue").click(popup_remove_redirect(nextpage));
// display warning window
popup_position(400, 300);
$("#popup_window").css({ display: "block" }); //for safari using css instead of show
$("#continue").focus();
$("#continue").blur();
}
function popup_remove_redirect(nextpage) {
$("#popup_window").fadeOut("fast", function () { $('#popup_window,#popup_overlay').trigger("unload").unbind().remove(); });
$("body", "html").css({ height: "auto", width: "auto" });
$("html").css("overflow", "");
window.location.href = nextpage;
}
(我将 window.location.href 添加到我的标准弹出窗口删除代码中,但我尝试了其他方法,包括通过单击按钮触发两个操作。)
下面是VB.NET调用代码:
If Status = "DOWN" Then
Dim clsUtility As New Utility
clsUtility.Emailer("email@company.com", "email@company.com", "", "", "The Service Is Down!", "Please investigate")
Dim ScriptString As String = "<script language='javascript'>"
ScriptString += "warn_redirect('Some warning message.', 'Warning', 'AnotherPage.aspx');"
ScriptString += "</script>"
ClientScript.RegisterStartupScript(Me.GetType, "warnscript", ScriptString)
'Response.Redirect("AnotherPage.aspx?ID=" & Session("SelKey") & "&UN=" & Header1.UserNumber) //this didn't work either
End If
最佳答案
您将在此处立即调用您的函数:
$("#continue").click(popup_remove_redirect(nextpage));
你想做的事:
$("#continue").click(function() { popup_remove_redirect(nextpage); });
关于javascript - 需要 jQuery 方法在按钮单击后重定向 - ASP.NET、VB.NET、jQuery、Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20197740/