繁体   English   中英

在浏览器上打开 html 链接以阅读 PDF 文件被浏览器阻止

[英]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 ),它将在浏览器中打开而没有任何问题.

如何解决这个问题?

小提琴演示

您可以使用代理脚本(在同一个域中)绕过它:

PHP 示例

将下面的代码保存为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.

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