By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,694 Members | 1,622 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,694 IT Pros & Developers. It's quick & easy.

Can JS bring up the Open With/Save As dialog?

P: n/a
kj


Hi. Suppose that a JavaScript script running on some browser has
some data in a variable (e.g. a large chunk of text retrieved via
Ajax from a remote server). Is there a way for the script to cause
the browser's Open With/Save As dialog to come up to view this
data?

TIA!

Kynn

--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
* kj wrote in comp.lang.javascript:
>Hi. Suppose that a JavaScript script running on some browser has
some data in a variable (e.g. a large chunk of text retrieved via
Ajax from a remote server). Is there a way for the script to cause
the browser's Open With/Save As dialog to come up to view this
data?
You could try to simulate it by navigating to an address that either has
an unknown internet media type or alternatively a 'Content-Disposition'
header with the right values (e.g., by posting the data to some web site
first). An option for the former could be:

window.location.href = 'data:application/octet-stream,...';

where the ... is the properly encoded data you wish the user to save.
You could also use whatever right mime type you have and have the user
right-click save-as, but I don't think you can trigger that from script.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Jun 27 '08 #2

P: n/a
Lee
On Jun 2, 7:44*am, kj <so...@987jk.com.invalidwrote:
Hi. *Suppose that a JavaScript script running on some browser has
some data in a variable (e.g. a large chunk of text retrieved via
Ajax from a remote server). *Is there a way for the script to cause
the browser's Open With/Save As dialog to come up to view this
data?

TIA!

Kynn

--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
This may help you http://www.tek-tips.com/viewthread.c...1171273&page=1
but it looks like you may run into security issues.

Can you not write the file to the server and let the user download it
Bjoern has pointed out?
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.