HTML-使用按钮在新窗口中打开本地PDF [英] HTML - Open local PDF in a new window using a button

查看:152
本文介绍了HTML-使用按钮在新窗口中打开本地PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

给出以下代码:

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

它只是打开一个about:blank页面.怎么了?

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

推荐答案

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

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.

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

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

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

这篇关于HTML-使用按钮在新窗口中打开本地PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆