javascript HTML - 使用按钮在新窗口中打开本地 PDF

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33434853/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 16:27:58  来源:igfitidea点击:

HTML - Open local PDF in a new window using a button

javascripthtmlbutton

提问by giroxasmnl

I'm trying to open a pdf file using a button in my project.

我正在尝试使用项目中的按钮打开 pdf 文件。

Given this code:

鉴于此代码:

 <button type=submit class="btn btn-danger" onclick=" window.open('file:////C:\Users\data'); return true;"> PDF </button>

It just opens a about:blank page. What seems to be wrong?

它只是打开一个 about:blank 页面。似乎有什么问题?

采纳答案by Sam Willis

You shouldn't be linking to a local file on your own pc. You need to upload the file to your server, like you would do with images, and then link to the path that you place it in.

您不应该链接到您自己电脑上的本地文件。您需要将文件上传到您的服务器,就像处理图像一样,然后链接到您放置它的路径。

You should also be able to use target="_blank"for this rather than onclick. Here is an example set up for the html:

您还应该能够为此使用target="_blank"而不是 onclick。这是为 html 设置的示例:

<a href="/books/a-great-book.pdf" target="_blank">