我知道如何在wordpress中提交联系表单7构建表单后将表单重定向到另一个页面 . 所以我可以将它重定向到pdf文件 . (然后在浏览器中打开)
但我希望在提交后直接下载 . 没有重定向 .
我用来将表单重定向到pdf文件的代码是:
on_sent_ok: "location = 'url to pdf file here';"
完美的方式是表单将消失并在表单的位置上说谢谢你注意并开始下载PDF文件
您可以通过在PDF目录中添加此.htaccess文件来强制直接下载pdf而不是在服务器上查看 .
.htaccess - 这将强制下载PDF
<FilesMatch "\.(?i:pdf)$"> ForceType application/octet-stream Header set Content-Disposition attachment </FilesMatch>
或者你可以尝试javascript(未经测试)
function force_download( file ) { pdf = window.open(file, '', 'left=100,screenX=100'); pdf.document.execCommand('SaveAs', 'null', 'myfile.pdf'); pdf.close(); } on_sent_ok: "force_download('pdf_url_here');"
1 回答
您可以通过在PDF目录中添加此.htaccess文件来强制直接下载pdf而不是在服务器上查看 .
.htaccess - 这将强制下载PDF
或者你可以尝试javascript(未经测试)