What is the best cross browser way to open a download dialog (lets assume we can set content-disposion:attachment in the headers) without navigating away from the current page, or opening popups, which doesnt work well in IE6.
views:
362answers:
4
+2
A:
Put this in the HTML head section, setting the url
var to the URL of the file to be downloaded:
<script type="text/javascipt">
function startDownload()
{
var url='http://server/folder/file.ext';
window.open(url,'Download');
}
</script>
Then put this in the body, which will start the download automatically after 5 seconds:
<script type="text/javascipt">
setTimeout("startDownload()",5000); //starts download after 5 seconds
</script>
(From here.)
gclaghorn
2009-06-30 22:44:13
that doesnt work, because in IE6, if the user clicks "save" the file is saved, but the popup stays open. This is not acceptable.
mkoryak
2009-06-30 22:57:16
A:
How about:
<meta http-equiv="refresh" content="5;url=http://site.com/file.ext">
This way works on all browsers (i think) and let you put a message like: "If the download doesn't start in five seconds, click here."
If you need it to be with javascript.. well...
document.write('<meta http-equiv="refresh" content="5;url=http://site.com/file.ext">');
Regards
+2
A:
I always add a target="_blank" to the download link. This will open a new window, but as soon as the user clicks save, the new window is closed.
jao
2009-07-01 12:03:00
A:
A small/hidden iframe can work for this purpose.
That way you don't have to worry about closing the pop up.
Simon
2009-07-01 12:13:01