Forum Moderators: open

Message Too Old, No Replies

SVG/Javascript: How to save file?

         

Danae

12:24 pm on Nov 2, 2009 (gmt 0)

10+ Year Member



Hi!

I'm making a website where users can draw circles, polygons, etc. with SVG. Everything is handled with JavaScript. I'd like to add a feature that allows users to save their creation.

In PHP DOM there is a function saveXML() that returns XML document as string. Is there similar function for SVG/JavaScript? Or is there some other way to save dynamically created SVG file?

Thanks a lot for your answers!

Fotiman

6:34 pm on Nov 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld!
In order to get client browsers to download a file, I believe they need to receive the file with a mime-type that the browser is not configured to display/use. In other words, if your browser is capable of displaying .svg files, then when you click on a link to a .svg file, it will open in the browser. Alternatively, you may be able to right click on the link and select "Save As..." (or your browser's equivalent) to download the file and save it locally instead of displaying it in the browser.

Danae

8:04 am on Nov 3, 2009 (gmt 0)

10+ Year Member



Thanks (:

My purpose is to get SVG document to text and then send the text to PHP file that saves the text into file. The problem is that I don't know how to get SVG into text.

I found this place: [keith-wood.name...] There's a function toSVG that "serialises the current diagram into an SVG text document". I just have no idea how to use it - yet.

edit:
Wow, I got it. This does the trick:
var root = document.documentElement;
alert(new XMLSerializer().serializeToString(root));