简体   繁体   English

提交点击并重定向后直接下载pdf

[英]download pdf directly on submit click and redirect

I have a requirement in my system where a report is generated in pdf format on clicking the submit button thereby downloading it and when pdf is downloaded, the page should redirect to a new page. 我的系统中有一个要求,即单击“提交”按钮以下载报告时会以pdf格式生成报告,并且在下载pdf时,页面应重定向到新页面。 Right now i am able to open a window using window.open for pdf file which generates the pdf in new window and is downloaded ,and after that the old tab redirects to the new url. 现在,我可以使用window.open for pdf文件打开一个窗口,该窗口会在新窗口中生成pdf并下载,然后将旧选项卡重定向到新的url。

The process that i need is the download should happen without opening a new tab and then the page should redirect to new url. 我需要的过程是下载而无需打开新选项卡,然后页面应重定向到新的url。 I was able to do one thing but not both together. 我能够做一件事,但不能一起做。

Any suggestions would be helpful. 任何的意见都将会有帮助。

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);

You can use a solution very similar to this one. 您可以使用与此解决方案非常相似的解决方案。 But simply, instead of using a new window, just use an inline frame, aka iframe : 但简单地说,不用内联窗口,而要使用内联框架,也就是iframe

And don't do the redirect directly. 并且不要直接进行重定向。 Wait until the iframe is laoded. 等待iframe装满。 To do show, subscribe to its onload event, like shown here: 要显示,请订阅其onload事件,如下所示:

Ie, do the redirect inside the iframe 's onload. 即,在iframe的onload中进行重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM