I am looking for a way to save a couple of files created with JavaScript on the clients computer. I want him to be able to choose a folder (similar to open/save folder dialog), and then write the fil开发者_运维问答es there. This obviously requires three things:
- Ability to popup such a dialog.
- Ability to write on the client's computer (signed applets?)
- Some way to interact with JavaScript because it knows the filenames and contents to write.
Is this possible or should I just stop dreaming?
It sure is possible.
One way is to use a signed applet, but if your users are willing to upgrade to Java 1.6.0_10+, a signed applet is not needed. Since 1.6.0_10 (the Next Generation Java Plug-In), JNLP API services are available to embedded applets. Here is a demo. of the JNLP file services.
I see the other reply has already covered the applet/JS interaction.
It is possible with a signed applet.
I'd probably do it the other way around, let the javascript code pass all the data to the applet and the applet should open a FileDialog
and write the file.
Calling javascript from java can be achieved via `JSObject, calling Java from Javascript is explained here
If your applet is signed you can do everything that you can do in regular application. You can open "File dialog" but it will be the Java's dialog, not the same that is opened when user pushes "browse" button of tag <intput type"file"/>
. Obviously signed applet can perform read and write operations with user's disk.
All applets (either signed or unsigned) may call javascript using JSObject
. You just have to say MAYSCRIPT="true" into applet tag.
I think that you cannot open the browser's "file open" dialog applet. Actually you even cannot open it using regular javascript. (I'd be happy to know that I am wrong at this point but I spent some time trying to do this and failed).
精彩评论