Can I configure an HTML button to always “save target as” when being clicked?

ε祈祈猫儿з 提交于 2019-12-24 19:04:29

问题


I'm generating CSV files in an application I'm doing.

Right now I'm displaying the finished files as plain HTML links, but I would like to make them buttons.

Question:
Is it possible to configure a button so it triggers the "right click & save target as" action, because clicking on the button will try to load the CSV file in the browser.

If not, is there another way to prevent the button target being clicked and maybe display an alert, so the link is not being followed.

Thanks!


回答1:


I'm not sure how you plan to do this without some server help, but you could take a look at this and see if it helps you get somewhere http://www.jtricks.com/bits/content_disposition.html




回答2:


You can force download using PHP

<?php
header('Content-type: application/force-download');
$musicfile=$_GET["musicfile"];
if(file_exists($musicfile))
{
header('Content-Disposition: attachment; filename="'.$musicfile.'"');
readfile($musicfile);
}
?>


来源:https://stackoverflow.com/questions/11723971/can-i-configure-an-html-button-to-always-save-target-as-when-being-clicked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!