简体   繁体   中英

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

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

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?

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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