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

K

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
 
B

Bjoern Hoehrmann

* 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.
 
L

Lee

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

This may help you http://www.tek-tips.com/viewthread.cfm?qid=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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top