[英]Why IE cannot close tab on “Cancel” button click c#
我有这个取消按钮:
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Cancel" />
我想单击该按钮将关闭当前窗口,因此在代码后面:
protected void Button1_Click(object sender, EventArgs e)
{
string jScript = "<script>window.close();</script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "keyClientBlock", jScript);
// Response.Write("<script>parent.close_window();</script>");
}
但是我没有在IE浏览器中看到该窗口选项卡关闭。 有什么可以纠正的吗?
当您只需将附加到js / jQuery中的按钮click事件时,为什么要在服务器端进行操作?
除非通过window.open()
方法生成了窗口本身,否则由于浏览器的安全性设置,这可能行不通,因此,如果绝对必要,则需要使用替代方法。
<script type="text/javascript">
$('#button').click(function(e){
e.preventDefault();
window.open('','_self').close();
});
</script>
<button id="button" value="close" />
function CloseWindow() {
window.open('','_self').close();
}
背后的代码
protected void Button1_Click(object sender, EventArgs e)
{
string jScript = "<script>CloseWindow();</script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "keyClientBlock", jScript);
}
我也建议您使用javascript创建一个函数,然后用您的代码调用它,如果您不打算在.cs方面做任何事情,我们DGibs会回答。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.