...

View Full Version : strange saveAs behaviour



amitye
12-10-2009, 06:35 AM
Hi,

I am trying to make an xml file download from my website, so the saveAs window will be open, I checked the forum and found the following code. but instead of saving the xml file it saves the html file. any clue???
are there other ways to do it ?



<html>

<script type="text/javascript">
function forceSaveAs (filename){
document.execCommand('SaveAs',null,filename)
}

</script>
<a href='/DVEConfiguration.xml' onclick=\"forceSaveAs('DVEConfiguration.xml_export'); return false\">Download</a>
</html>


I also try to send the xml with the following header but with no success



print "Content-type: application/octet-stream\n\n";
print "Content-Disposition: attachment; filename=file.xml;"

Old Pedant
12-10-2009, 08:31 AM
Because the command "SaveAs" is used to implement the Save As from the FILE menu. And *that* Save As is designed to save the HTML page.

If you want to try to force the file to be saved, instead of opened, you pretty much have to do that form server-side code. PHP or JSP or ASP or similar.

amitye
12-10-2009, 11:36 AM
Hi,

I am trying to make an xml file download from my website, so the saveAs window will be open, I checked the forum and found the following code. but instead of saving the xml file it saves the html file. any clue???
are there other ways to do it ?



<html>

<script type="text/javascript">
function forceSaveAs (filename){
document.execCommand('SaveAs',null,filename)
}

</script>
<a href='/DVEConfiguration.xml' onclick=\"forceSaveAs('DVEConfiguration.xml_export'); return false\">Download</a>
</html>


I also try to send the xml with the following header but with no success



print "Content-type: application/octet-stream\n\n";
print "Content-Disposition: attachment; filename=file.xml;"


found the probelm.
it was the extra "\n" at the end of the first line
and the lack of one in end of the second line



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum