javascript - How do I save/export an SVG file after creating an SVG with D3.js (IE, safari and chrome)? -
I currently have a website D3 and I want the user to have the option of saving SVG as SVG file Could. I'm using crowbar.js to do this, but it only works on Chrome. None of Safari and IE are used to download the file How do I download a SVG file based on the SVG element on my website in Safari, IE and Chrome? There are 5 steps I use these methods often for inline SVG output. click () used in crowbar.js method has been denied.
var e = document.createElement ('script'); If (window.location.protocol === 'https:') {e.setAttribute ('src', 'https://raw.github.com/NYTimes/svg-crowbar/gh-pages/svg-crowbar.js '); } Other {e.setAttribute ('src', 'http://nytimes.github.com/svg-crowbar/svg-crowbar.js'); } E.setAttribute ('class', 'SVG-Caubawar'); document.body.appendChild (E);
// get the SVG element Var svg = document.getElementById ("SVG"); // Get STG Source Var serializer = New XMLSerializer (); Var source = serializer.serializeToString (SVG); // Name Add spaces if (! Source.match (/ ^ & gt; svg [^ & gt;] + xmlns = "http \: \ / www \ .w3 \ .org \ / 2000 \ / svg" / )) {source = source. Replace (/ ^ & lt; svg /, '& lt; svg xmlns = "http://www.w3.org/2000/svg' '); } If (Source! (^ / ^
Comments
Post a Comment