Javascript save as command problems.


  • Hey guys and gals, having some issues with the saveas command in Javascript...

    I have been developing a simple ie based internal message board system which essentially uses javascript to dynamically add and delete content from the same webpage. I have had no problems with these functions until I have come to try and save over the file.

    I need some javascript which is able to save the modified content over the current file ie is viewing.

    Using the execCommand I have managed to prepare the content for saving, but I am unable to make the execCommand to point the file explorer prompt to the correct default file. I have used the following javascript code:

        var newHtml = document.documentElement.outerHTML;'text/html','replace');
        document.execCommand('SaveAs', false, "C:/iSpace/users/default.htm");

    My first question is: why does this code keep defaulting the dialogue back to the desktop directory, and second, is there any possible way to suppress the prompt all together and just save the updated page with just one click.

    Java isnt my strongest subject, so I would apreciate it if anybody who can spell out a solution to these problems...

    Thanks... Matt
    Sunday, January 06, 2008 8:35 PM

All replies

  • It would a security risk to allow JScript code running in a browser to be able to save a file to your hard disk without your intervention.  Similarly its probably not a good idea to even allow such code to suggest where the file should be saved.  "C:\windows\system32\somecriticalfile.dll" would only require the user to not be paying attention and simply click save and damage can be done.

    Thursday, March 13, 2008 9:54 AM
  • Microsoft documents the path should be:
    Although this doesn't look to have any affect on the starting path.

    I havn't been able to prevent the popup of the path-dialog either.
    Software developer
    Saturday, March 14, 2009 1:54 AM