dslreports logo
 
    All Forums Hot Topics Gallery
spc
Search similar:


uniqs
171573

franzcatch
Mad A
Premium Member
join:2003-06-24
Saint Louis, MO

1 edit

franzcatch

Premium Member

Opening a file download dialog from a JavaScript function.

I am developing a webpage and want my users to be able to download a file from me.

I know I can put a link on the page for the user to click like this:
<a href="download/VB6IP.zip">Download</a>  
 

However, I would like to launch the dialog from a JavaScript function.
Is there an easy way to accomplish this?
OZO
Premium Member
join:2003-01-17

OZO

Premium Member

Any reason why do not use good old way?
For security reasons users may have JavaScript turned off...

cowboyro
Premium Member
join:2000-10-11
CT

2 edits

cowboyro to franzcatch

Premium Member

to franzcatch
in the HEAD section:
<script type="text/javascipt">
function startDownload()
{
var url='http://server/folder/file.ext';  
window.open(url,'Download');
}
</script>
 
in BODY
<script type="text/javascipt">
setTimeout("startDownload()",5000); //starts download after 5 seconds
</script>
 

or if you have just 1 download location you can combine the 2 in the body:

<script type="text/javascipt">
setTimeout("window.open('http://server/folder/file.ext','Download')",5000); 
</script>
 

Edit: I wouldn't worry so much about the 0.01% that are paranoid and turn off javascript... But *do* provide a link in case a popup blocker kills the download.