Forum Moderators: open

Message Too Old, No Replies

Saving a file in Mozilla through Javascript

Saving a text file, javascript, mozilla

         

Poonam

1:01 pm on May 5, 2008 (gmt 0)

10+ Year Member



Hi,

I want to open a SaveAs dialog box in Mozilla through Javascript with a default file name initialized to "sample.txt".
If I use saveDocument by default the file name is "sample.html".

Can you please help me to find a solution to this problem?

Thanks a lot for your help.

httpwebwitch

1:38 pm on May 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



IE has a "Save As..." trigger:
<a href="#" onclick="javascript:document.execCommand('SaveAs','1',null);">Save As...</a>

However if you're asking the user to save a file, you don't need any fancy tricks; just make a link to the file on your server, and the browser takes care of the rest.

If the file being requested has an "undisplayable" MimeType, the user will be prompted to save it.

"displayable" = [HTML, TXT, JPG, SWF, etc]
"undisplayable" = [JS, ZIP, XYZ, etc]

Poonam

3:26 am on May 6, 2008 (gmt 0)

10+ Year Member



Hi,

Thanks for the reply. Actually, I cannot save the file on server as the content of the file is dynamically generated at client side. I was able to successfully perform this functionality in IE by using execCommand. I want to achieve similar performance on Mozilla too.
The content should be saved in a text file.

Thanks