【问题标题】:How to close browser tab with alert message in c#如何在 C# 中关闭带有警报消息的浏览器选项卡
【发布时间】:2015-05-04 08:16:34
【问题描述】:

我一直在尝试使用下面的代码执行但没有显示消息框并且选项卡也没有关闭。

ScriptManager.RegisterStartupScript(this, this.GetType(), "Messagebox", "alert('Record Deleted successfully.Note: This tab is now getting close');", true);

所以我只是从上面的代码中删除“警报”代码,然后它开始执行并关闭选项卡。但是我也想显示通知消息框怎么办?

ScriptManager.RegisterStartupScript(this, this.GetType(), "Messagebox", "window.close();", true);

【问题讨论】:

标签: c#


【解决方案1】:

只需将两个调用合并为一个,然后一个接一个地调用:

ScriptManager.RegisterStartupScript(this, this.GetType(), "Messagebox", "alert('Record Deleted successfully.Note: This tab is now getting close');window.close();", true);

【讨论】:

  • 不确定你在问什么,但是:2 个 javascript 片段被粘在一起了。
  • @MatteoSp 不能一次执行两个脚本。
  • 你能澄清一下“不能一次执行两个脚本”吗?
【解决方案2】:

从 javascript 尝试

<script type="text/javascript">
    function Showalert() {
        alert('Call JavaScript function from codebehind');
        window.close();
    }
</script>

然后从你想要的代码隐藏端调用它。

ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "Showalert();", true);

希望这会对您有所帮助。 谢谢。

【讨论】:

    【解决方案3】:

    这样写..

    ScriptManager.RegisterStartupScript(this,GetType(),"showalert","alert('Only alert Message');",true);
    

    【讨论】:

    • ScriptManager.RegisterStartupScript(this, this.GetType(), "Messagebox", "alert('Record Deleted succeeded.Note: this tab is now getting close');", true); ScriptManager.RegisterStartupScript(this, this.GetType(), "Messagebox", "window.close();", true);
    猜你喜欢
    • 2021-11-25
    • 2022-07-11
    • 2015-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-19
    • 1970-01-01
    • 2013-04-24
    相关资源
    最近更新 更多