【问题标题】:Can I delay window.open()?我可以延迟 window.open() 吗?
【发布时间】:2010-04-02 18:22:43
【问题描述】:

这是我的基本问题。

用户点击保存按钮。
使用 Ajax 通过代码隐藏保存内容。
然后打开一个新窗口,从数据库加载内容。

我只需要一种在内容保存之前不打开窗口的方法。现在它会立即打开一个新窗口,并且内容尚未全部保存。

有什么想法吗?

编辑:
对不起,我想我应该更清楚。我正在使用 asp.net 更新面板,我单击的按钮会触发更新面板以将一些信息保存到数据库,然后我想打开一个新窗口来“预览”这些新数据。所以这就是我所拥有的,它不会中断,但也不会打开新窗口。

protected void lnkPreview_Click(object sender, System.EventArgs e)
{
      temp1 control = UpdatePanel1.ContentTemplateContainer.FindControl("template") as temp1;
      control.saveContent();

      string script = "<script language='javascript'>window.open('/preview.aspx', '_blank');</script>";
      this.Page.ClientScript.RegisterClientScriptInclude(this.GetType(),"ClientScriptStuff", script);
}

【问题讨论】:

  • 我不会使用 window.open()。还有其他对用户更友好的替代方案。

标签: asp.net javascript ajax updatepanel


【解决方案1】:

您的 AJAX 调用允许您有一个完成回调,该回调将在服务器回复时执行。

您需要在那里致电window.open
如需更多详细信息,请向我们展示您的代码。

但是,请注意弹出窗口拦截器。

【讨论】:

  • 我知道你在做什么,但我正在尝试通过更新面板进行操作。
【解决方案2】:

我会考虑在用户操作后立即打开一个空白/替代内容窗口,然后在回调完成时设置窗口位置。这样您应该更能免受弹出窗口阻塞的影响。

【讨论】:

    【解决方案3】:

    在 ajax 完成后使用回调将 db 内容加载到 MODAL 窗口中。

    使用带有 facebox 插件的 jQuery 的示例:

    $("form").submit(function(){
        var form = $(this);
        $.ajax({
            "url" : form.attr("action")||document.location.toString(),
            "type" : form.attr("method")||"get",
            "data" : form.serialize(),
            "success" : function(data){
                $.facebox({"ajax" : "popupwindowURL.htm?data="+data});
            }
        });
        return false;
    });
    

    我只想注意,你应该在上面的 sn-p 中添加一个错误回调。您还应该防止多次提交表单。

    【讨论】:

      【解决方案4】:

      将 window.open() 函数设置为来自 AJAX 结果的回调。

      【讨论】:

      • 这不会由用户操作启动,因此可能被弹出窗口阻止程序阻止。
      【解决方案5】:

      使用 Ajax 方法获取保存的响应,并在收到保存确认后触发 window.open。

      【讨论】:

        【解决方案6】:
        protected void lnkPreview_Click(object sender, System.EventArgs e)
        {
                 //Save the page content
        
                 //Open a page to preview the changes
                 ScriptManager.RegisterClientScriptBlock(UpdatePanelName, typeof(Page), "previewPage", "window.open('/preview.aspx');", true);
         }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-10-06
          • 1970-01-01
          • 2018-04-02
          • 2012-04-15
          • 2019-05-12
          • 1970-01-01
          • 2012-07-16
          • 2012-04-05
          相关资源
          最近更新 更多