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 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);   

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.

  1. Get inline SVG element in the output.
  2. Get the STV source by XMLSerializer.
  3. Name spaces of svg and xlink.
  4. Prepare the svg's URL data plan by encodeurIComponent method.
  5. Set some urls in the href attribute of the "A" element, and right-click the file to download the SVG file.
    // 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

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -