I am facing the problem that I want to have two buttons, you can open or download a PDF on a server like:
<button id="download">download pdf</button>
<button id="open">open pdf</button>
But I don't have any idea how to achieve this. I already found that:
<a href="x.pdf" download="x.pdf">PDF Download</a>
BUT: HTML5 download attribute is not working in all browsers and it needs to be cross browser save.
You can use the onclick
attribute with window.open("x.pdf");
or you move it into a own function.
You should take a look at this:
https://github.com/eligrey/FileSaver.js/
JavaScript file which allows for cross-browser download support
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.