php - DIV onClick event force download a pdf file - Stack Overflow

I want to make a DIV onclick which will open a dialog box to save a pdf file.Something like this (html5

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>

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>
Share Improve this question edited Aug 29, 2013 at 9:25 marcin asked Aug 29, 2013 at 8:21 marcinmarcin 971 gold badge3 silver badges10 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 9
<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');

Try:

<div onClick="window.location='path'; return false;">something</div>

You should set correct headers on server side which will determine view or download a file

The header sections of this kind of apps must be taking seriously if you want the to work, if you do not have those show by Michał Prajsnar, i say go back and put them in and try again.

You can just google that same thing and solutions on the fly.

try these :

http://www.amember./forum/threads/force-file-downloads-with-htaccess.14980/

http://webdesign.about./od/php/ht/force_download.htm

Try:

<div onClick="window.open('path', '_blank', 'fullscreen=yes'); return false;">something</div>

This works fine for me.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743640714a4482911.html

相关推荐

  • php - DIV onClick event force download a pdf file - Stack Overflow

    I want to make a DIV onclick which will open a dialog box to save a pdf file.Something like this (html5

    1天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信