最簡單的方法:在頁面上開啟下載視窗而不離開頁面
P粉432906880
P粉432906880 2023-08-23 20:52:33
0
2
469
<p>什麼是在不離開目前頁面或開啟彈出視窗的情況下(假設我們可以在頭部設定content-disposition:attachment),在各種瀏覽器中開啟下載對話方塊的最佳方式,而不會在Internet Explorer(IE) 6中出現問題。 </p>
P粉432906880
P粉432906880

全部回覆(2)
P粉803527801

這個javascript很好,它不會開啟一個新視窗或標籤。

window.location.assign(url);
P粉864872812

已經過去了7年,我不知道它是否適用於IE6,但它在FF和Chrome中會彈出OpenFileDialog。

var file_path = 'host/path/file.ext';
var a = document.createElement('A');
a.href = file_path;
a.download = file_path.substr(file_path.lastIndexOf('/') + 1);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!