How can I generate an xml file and allow the user to save it locally using javascript?
I am creating an XMl document using JavaScript and have to prompt the user to save it on their local machine.
This is the code I have at the moment:
var xmlWindow = window.open("", "");
xmlWindow.document.write("<node>data</node>");
This writes the xml to a new window which the user can then press file-> save to load.
- Is there an even nicer way to do this?
- Is there a way to set the mimeType of the new window so that the xml is displayed correctly?
- any way to specify the title, so when the user clicks save, the filename is set correctly?
note: should be compatible with most browsers (IE6, IE7, FF, Chrome).
0
source to share
2 answers
"save it locally": a tough call if you want to be compatible across browsers. See this post .
TiddlyWiki manages to do this for some browsers (not sure which ones it supports), but only by installing certain files by the user.
0
source to share