Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2009
    Posts
    16
    Thanks
    2
    Thanked 0 Times in 0 Posts

    strange saveAs behaviour

    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 ?

    Code:
    <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

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

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,184
    Thanks
    75
    Thanked 4,339 Times in 4,305 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Dec 2009
    Posts
    16
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by amitye View Post
    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 ?

    Code:
    <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

    Code:
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •