我正在使用这段代码。当我在主页上单击一个按钮时,会弹出这个弹出窗口。现在我希望在成功更改密码并重新加载主页时关闭弹出窗口,但是如果密码未更改,然后再次刷新弹出窗口。 这是代码.....
<asp:Textbox id="curnt_paswrd" textmode="Password" runat="server" size="30" />
<asp:Textbox id="new_paswrd" textmode="Password" runat="server" size="30" />
最佳答案
给你....
这是为了打开弹出窗口....
<html>
<head>
<script type="text/javascript">
var passwordPopup;
function popUpPassword()
{
passwordPopup = window.open("ChangePassword.aspx");
window.onbeforeunload = function()
{
alert("yay I reloaded!");
window.onbeforeunload = null;
}
}
</script>
</head>
<body>
<button onclick="popUpPassword();">Popup Password Change</button>
</body>
</html>
这用于重新加载主页并关闭弹出窗口....
public partial class ChangePassword : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void SubmitPassword_Click(object sender, EventArgs e)
{
bool passwordChanged = true;
if (passwordChanged)
{
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the client script is already registered.
if (!cs.IsClientScriptBlockRegistered(this.GetType(), "popUpPwScript"))
{
StringBuilder jscript = new StringBuilder();
jscript.Append("<script type=\"text/javascript\">");
jscript.Append("window.opener.location.reload(); window.close();");
jscript.Append("</script>");
cs.RegisterClientScriptBlock(this.GetType(), "popUpPwScript", jscript.ToString(), false);
}
}
else
{
//do something else
}
}
}
关于javascript - 如何关闭弹出窗口并在成功时将控制权返回到父页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3634664/