-1

How can i set left mouse click to save the doc (docx) document to my computer? At this moment its only opening doc file in a browser, i want to prevent that. How's that can be done?

<script type="text/javascript">
    function SaveAsMe() {
        e.preventDefault(); // prevent event onclick
        document.execCommand('SaveAs');
    }
</script>

<a href="sites/mydoc.doc" onclick="SaveAsMe()">download doc file</a>

The code above is not working - still opening that doc file in a browser... Thanks in advance.

i can set that on my test.php page:

header("Content-Type: application/vnd.ms-word; charset=windows-1251");
header("Content-Disposition: attachment; filename=".$node->field_book[0]['filename'].".doc");

but then when i load test.php it always asks me to save that file... how can i make to work that only for links that leading to doc||docx files?

Alexander Kim
  • 15,388
  • 17
  • 88
  • 141

1 Answers1

1

Add the following to your .htaccess file in your sites directory:

<Files *.doc> ForceType application/octet-stream Header set Content-Disposition attachment </Files>

This will force it to download, and you can use a regular <a href=''> to link to the file without any JS intervention.

Kavi Siegel
  • 2,934
  • 2
  • 23
  • 33