Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Autostarting download

Status
Not open for further replies.

jakeyg

Programmer
Mar 2, 2005
517
GB
I'm trying to create a page which gives you a download dialog box for a file as soon as you open the page

I've got the following code which when works fine as an ASP or html file downloading an .EXE but I'm trying to make an auto download for a .PDF and/or .TXT file.

Can you only autodownload .EXE files?

This is the code I've got that works for .EXE

<html>
<head>
</head>
<BODY>
<script language="JavaScript" type="text/javascript">
<!--
function beginDownload()
{
idl = -1;
idl = location.search.indexOf("idl=n");
if (idl < 0) document.write('<iframe height="0" width="0" src=" }
window.onLoad=beginDownload();
//-->
</script>

</body>
</html>
 
AFAIK, is the user has the extension associated to any plugin in his browser, the file will not be downloaded but displayed.

Cheers,
Dian
 
I believe it is the MIME type, not the extension. Either way, you can't do it with JavaScript. There are, however, methods using server-side technologies like ASP.NET.

Adam
 
So something should be shown regardless??? If it's a .TXT file, should an instance of notepad appear or will the contents of the textfile be shown in the browser window?
 
If you use the code in the link I posted, the download dialog box will be shown. What the user does with the file after that is up to them. Isn't that what you said you wanted?

Adam
 
Sorry, the link didn't show up earlier on :-(
Sounds like it's what I'm after I'll give it a try in the morning
thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top