Click to See Complete Forum and Search --> : Click to save PDF
Dementia1313
12-17-2002, 11:14 AM
Is there a way (with Javascript or something) to have a link or button or something to a PDF file, which will bring up a save dialog rather than loading it in the browser? (I know all about right-clicking it, I'm dealing with very low-tech users here.)
Thanks!
Sceiron
12-17-2002, 12:58 PM
The method in which the browser handles the file is not up to you or your script. To the best of my knowledge, there is no way to "force" a browser to ask the user to save a file or open it specifically.
Hi,
you can create a temporary window like:
<html>
<script language="JavaScript">
<!--
function saveas()
{
w = window.open("thePdfFile.pdf","SaysaMe"); // makes a new window, open pdf temporary;
w.document.execCommand("SaveAs",null,"SaveAsName.pdf"); //executes the save as command
w.close();
}
//-->
</script>
<body>
<button onClick="saveas()">Save pdf</button>
</body>
</html>
aepstar
12-17-2002, 02:14 PM
Unfortunatelly ur example swon doesn't work in ie6.1
What u really need to do dementia1313 is to explain ur low-tech users how to "save target as" option capabilities. Or just zip the pdf file. If u have the right zip tools u can even make it an auto unzipper!!!
Charles
12-17-2002, 02:21 PM
Se the discussion at http://forums.webdeveloper.com/showthread.php?s=&threadid=919.
aepstar, thanks, i have not tested in ie6.1 only in ie6.0 and 5.5.
And sure, the best way for downloading is to zip the files!
But that's probably not the desired function for dementia
Charles
12-17-2002, 03:00 PM
The best solution is to set the Content-Type field of the HTTP response header to application/octet-stream.
aepstar
12-18-2002, 02:00 AM
Originally posted by swon
aepstar, thanks, i have not tested in ie6.1 only in ie6.0 and 5.5.
And sure, the best way for downloading is to zip the files!
But that's probably not the desired function for dementia
Sorry, I am kinda stupid, what do you mean exactly.
Will it be asp code? Dementia asks for javascript code though!
Charles
12-18-2002, 04:31 AM
Originally posted by aepstar
Sorry, I am kinda stupid, what do you mean exactly.
Will it be asp code? Dementia asks for javascript code though! He's writing about compressing the file and saving it with the extension ".zip". The extension causes the server to change the Content-Type field of the HTTP response header to application/zip which causes the user's browser to save the file if it doesn't know what to do with that kind of a file. The problem, however, is that the user will have to de-compress the file to use it. If you change the Content-Type field of the HTTP response header to application/octet-stream then the user's browser will save it and the user will not need to do anything to get it to be readable by Acrobat.
aepstar
12-18-2002, 06:12 AM
Originally posted by aepstar
Sorry, I am kinda stupid, what do you mean exactly.
Will it be asp code? Dementia asks for javascript code though!
so actually the dude ment saving file as .zip? I think thats already said above in the postings by someone.
Charles
12-18-2002, 06:27 AM
But if you save it with the '.zip' extension and if the user is using windows then when the user tries to view the file Windows will try to decompress it. So you first have to compress it as a 'zip' file. That's why it's much better to simply change the Content-Type field of the HTTP response header to application/octet-stream.