Save/Open file Locally

They have: 19 posts

Joined: Oct 2000

Hi,

Does anyone know if there is a way to generate a "button" that when clicked will pop up a windows savefile/open file dialoge?

(Similar to the "" but for saving/opening a file locally, not uploading to a server)

The reason being is I want to be able to enter text into a form's textarea and save the text to the user's computer.

Cheers!

Denise Smiling

They have: 9 posts

Joined: Oct 2000

Sorry, there is no such thing in JavaScript or any language which comes from a web server, because of security reasons. You may want to write and sign a Java applet which does this (see http://developer.netscape.com/security/), but there is no other way to do this through a web page.

They have: 19 posts

Joined: Oct 2000

Hi,

Thanks for the feedback. I will look into applets but what do you mean by "sign" an applet?

Denise

They have: 12 posts

Joined: Oct 2000

Is this what you mean?

<script>
function saveAs(){
if (document.all) {
var WebBrowser = '';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
WebBrowser1.ExecWB(4, 1);
//WebBrowser1.outerHTML = "";
}
}

</script>

Or


Save This Page

They have: 19 posts

Joined: Oct 2000

Hi Hugh,

Yeah, thanks, this is getting along the right lines.

If it's possible to do this, is it somehow possible to:

1) Save a specific "textarea" of a designated form, instead of the whole page? (ie: document.myform.mytextarea.value)

2) Put the name I want the file to be saved as in the pop up window with the extension ".txt" instead of .htm/.html?(instead of Untitled1.htm by default)

Yours hopefully,

Denise Smiling

They have: 9 posts

Joined: Oct 2000

This is as far as I got, but IE just gives me an error "This web page could not be saved":

<HTML>
<HEAD>

&lt;script&gt;
function saveAs(){
if (document.all) {
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.ifr.document.write(WebBrowser);
document.ifr.document.write(document.theform.texta.value);
document.ifr.document.close();
document.ifr.document.all.WebBrowser1.ExecWB(4, 1);
//WebBrowser1.outerHTML = "";
}
}

&lt;/script&gt;

<HEAD>
<BODY>
<iframe name="ifr">
</iframe>
<FORM name="theform">
<textarea name="texta"></textarea>
<INPUT type="button" value="Save this page" onclick="saveAs(); return false"></FORM>

<BR>Or<BR><BR><BR>

<A href="save-this-page.htm" onclick="saveAs(); return false">
Save This Page</A>
</FORM>

</BODY>
</HTML>
'

They have: 19 posts

Joined: Oct 2000

Hi Voicebox,

Cheers for giving it a go.

This actually saves as a .txt file but includes the whole page not just the internal frame. I'm sure there's a way!

Denise

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.