如何設置鼠標左鍵單擊將doc(docx)文檔保存到我的計算機上?在這一刻,它只有在瀏覽器中打開doc文件,我想阻止它。那可以怎麼做?如何用左鍵單擊jQuery或javascript下載doc,docx文件
<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>
上面的代碼不工作 - 仍然打開一個瀏覽器,doc文件... 在此先感謝。
我可以設置我的test.php頁:
header("Content-Type: application/vnd.ms-word; charset=windows-1251");
header("Content-Disposition: attachment; filename=".$node->field_book[0]['filename'].".doc");
但後來當我加載test.php的它總讓我保存該文件...我怎樣才能讓工作只爲導致doc || docx文件的鏈接?
這必須在服務器上進行配置。這是否取決於您使用LAMP的服務器/語言? IIS/.NET? – 2012-03-07 18:57:17
Apache 2.2/PHP – Heihachi 2012-03-07 18:58:16
[強制使用PHP下載文件](http://stackoverflow.com/questions/1465573/forcing-to-download-a-file-using-php) – 2012-03-07 18:59:17