2

I want to implement dynamic, client side file generation in javascript. Is it possible? For example, a user pushes a button and the script suggests to download the generated file.

asked Sep 1, 2009 at 12:17

3 Answers 3

4

Not possible without a server side script that will return a response of the proper mime-type.

answered Sep 1, 2009 at 12:19
Sign up to request clarification or add additional context in comments.

5 Comments

NOT TRUE - You can use FSO to do this IE (only text files) & Java Applet to do this in any other browser - of course you'll have security issues to take care of. The bottom line - it's doable.
Sorry, let me rephrase that... NOT PRACTICAL. Why go through all the trouble to do it client side when a simple server side solution will do. What about firefox, Opera, Chrome, Safari etc. Can you guarantee it will work on all these. Sometimes being able to do something doesn't mean it should be done.
It's not recommended - correct, but maybe it's a must for the system he plans. Anyway, it's not your duty to decide that - its his only.
I would be curious to see why a company would want to implement such a solution. And as a developer why they wouldn't be put straight on this issue. One of the worst things you can do is to say "YES i can do this" when its plainly a bad idea. I think the best solution would be to tell your boss no can do!
I am not deciding anything for him. I think the point of stack overflow is provide the best solutions to every problem and let the person decide which he feels works best. ANd in this case, he has.
2

It depends a bit on what kind of file. You can generate an HTML file by opening a window and writing to it; the user can then download it via File | Save As on most browsers.

A text file can be generated and loaded into a textarea element, and then the user can either manually copy the file, or there are various ways to copy it to the clipboard (you could even keep the textarea hidden and just offer the copy button). Search for "javascript clipboard" for various ways to do that; here's one of the first lnks that comes up for that part of it.

Binary files will probably need to be handled server-side.

answered Sep 1, 2009 at 12:22

Comments

1

You can always use FSO to generate a text-oriented (binary won't work) file on the client's computer, return the link and download it.

Be aware that it will only work for IE (ActiveX) and you will be asked for more security rights.

Good luck.

answered Sep 1, 2009 at 12:24

4 Comments

Two things: 1) That's a Windows-only solution, and 2) Even in IE, it will only work if you have enhanced security rights.
That's right. He didn't specify any specific "wants" - so I figured that everything goes and gave my best solution.
I agree with T.J. Delivery of such a solution is impractical, and will cause more head aches in the long run than doing it the proper way with a server side solution. Its also a guarantee that most users will not know how to change their security settings.
Who are you to decide whether it's practical or not? Do you know the person who asked the question? Do you know for what cause he might need it? NO, You don't. You're right, using FSO is not recommended, but answering NO, YOU CAN'T is the worse answer you can give him.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.