DIV onClick 事件强制下载pdf文件 [英] DIV onClick event force download a pdf file
本文介绍了DIV onClick 事件强制下载pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做一个 DIV onclick,它会打开一个对话框来保存 pdf 文件.
像这样(html5 a href):
download
但在 DIV 上使用 onclick 事件.
我试过了,但没有用:
<div onClick="window.location='path' download">something</div>
解决方案
something
pdf.php:
I want to make a DIV onclick which will open a dialog box to save a pdf file.
Something like this (html5 a href):
<a href="path" download>download</a>
but using onclick event on DIV.
i tried but it's not working:
<div onClick="window.location='path' download">something</div>
解决方案
<div onClick="window.location=location/to/file/pdf.php">something</div>
pdf.php:
<?php
header('Content-disposition: attachment; filename=your_file.pdf');
header('Content-type: application/pdf');
readfile('path/to/your_file.pdf');
这篇关于DIV onClick 事件强制下载pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文