[英]Opening a html link to read a PDF file on browser is blocked by browser
我无法通过 html 链接在浏览器的选项卡中打开 PDF。
<a href="https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf" target="_blank">PDF</a>
问题:
但是,如果我直接在浏览器上打开链接( https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf ),它将在浏览器中打开而没有任何问题.
如何解决这个问题?
您可以使用代理脚本(在同一个域中)绕过它:
将下面的代码保存为test.php
,并使用php -S localhost:1234 test.php
启动服务器。 转到http://localhost:1234
。
if(isset($_GET['url']) && strpos($_GET['url'],"http") > -1) {
header('Content-type: application/pdf');
echo file_get_contents($_GET['url']);
exit;
}
?>
<a href="?url=https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf" target="_blank">PDF</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.