The easiest way: open the download window on the page without leaving the page
P粉432906880
P粉432906880 2023-08-23 20:52:33
0
2
470
<p>What is the best way to open a download dialog in various browsers without leaving the current page or opening a popup (assuming we can set content-disposition:attachment in the header) Problems will occur in Internet Explorer (IE) 6. </p>
P粉432906880
P粉432906880

reply all(2)
P粉803527801

This javascript is fine, it doesn't open a new window or tab.

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

It's been 7 years and I don't know if it works in IE6, but it pops up the OpenFileDialog in FF and Chrome.

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);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!