我在后端方面有以下代码。 (为了到达这里客户点击按钮,提交带有id的隐藏表单,打开带有... \ DownloadPDF地址的新空白页并开始下载。)
Chrome和Opera将其识别为弹出窗口并默认阻止它。在Firefox中,这段代码正常运行。如何避免它并让它们视为不是弹出窗口?
public FileContentResult DownloadPDF(Guid id)
{
var model = service.GetById(Guid);
var pdf = printService.CreatePDF(model);
var fileName =(model.Name + ".pdf").Replace(" ", "_");
Response.AppendHeader("Content-Disposition", $"attachment; filename*=UTF-8''{Server.UrlEncode(fileName)}");
return new FileContentResult(pdf, "application/pdf");
}
Form that is submitted from front-end:
<form action="/Print/DownloadPDF" target="_blank" method="post" id="print-form">
<input type="hidden" name="id" id="document-id" data-bind="value: Id"/>
</form>