【发布时间】:2014-09-04 07:51:25
【问题描述】:
我的系统中有一个要求,即在单击提交按钮时以 pdf 格式生成报告,从而下载它,当下载 pdf 时,页面应重定向到新页面。 现在我可以使用 window.open 为 pdf 文件打开一个窗口,该文件在新窗口中生成 pdf 并被下载,然后旧选项卡重定向到新 url。
我需要的过程是下载应该在不打开新标签的情况下进行,然后页面应该重定向到新的 url。 我可以做一件事,但不能同时做。
任何建议都会有所帮助。
string strJSCPTText = string.Empty;
string url = clsAppConfig.SiteURL + "PDFReport.aspx?qid=" + objQ1.QId;
strJSCPTText += "window.open('" + url + "', 'popup_window', 'width=500,height=300,left=100,top=100,resizable=yes');";
strJSCPTText += "window.location.href = '" + clsAppConfig.SiteURL + "QList.aspx" + "';";
ClientScript.RegisterStartupScript(this.GetType(), "script", strJSCPTText , true);
【问题讨论】:
-
能否将 location.href 设置为服务器上的文档 url?如果是这样,用户将获得打开/另存为提示。
-
您可以使用 iframe 并将其源设置为您的 PDF。
-
将window.open(不知道为什么location.href)更改为pdf下载的document.URL没有任何作用,它既不下载也不重定向
-
我确实尝试在从代码隐藏动态设置 src 后使用 iframe,重定向发生但 pdf 下载没有。
-
问题是你没有等到 iframe 被加载。显示我更新的答案。
标签: c# javascript asp.net pdf redirect