I made a map editor for my game, the code is generated to a div with id “code”. I am wondering how to generate a javascript file with this code. Obviously i have to get the text of the code div. var code = $("#code").text(); will work. But now i want to generate and download javascript file with this code. Is it even possible to generate/download a file with only javascript or do i have to use php?
I want to choose the folder and the name manually.
The short answer to your question is no. For security reasons browsers are very careful to NOT allow Javascript to do pretty much anything with the filesystem.
Flash however has no such limitations; check out: https://github.com/dcneiner/Downloadify. Of course, Flash has its own issues, such as the fact that mobile browsers tend to not support it (but since your use case is downloading a file, and mobile users probably won’t be doing that, this might not be an issue for you).
Other than Downloadify (or a similar Flash-based solution) your only options are Java applets (you don’t want to go down that road), browser plug-ins, or some sort of server-involvement (eg. as @Brad Christie described).