Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9217051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:33:17+00:00 2026-06-18T02:33:17+00:00

I have an svg that is generated in a page, I am not bringing

  • 0

I have an svg that is generated in a page, I am not bringing it in from an outside source. I want this svg to be downloadable for printing. Is there a way (using client side Javascript) to download a dom node as a text file? I am limited to dojo and d3 libraries for this project.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:33:18+00:00Added an answer on June 18, 2026 at 2:33 am

    Assuming the client is using a HTML5 web browser, this can be achieved pretty easily using <a>s download attribute. You will need to simulate a click with a MouseEvent on this element if you want the behaviour to be invoked by some other means, but the node does not have to be appended to the document. I’ve answered a similar question about this before, but here, set the <a>s href to the svg’s file location unless it is created dynamically ‒ in that case you would encode the text describing it to create a data URI.

    XML text describing a SVG can be obtained from it’s SVGSVGElement node using XMLSerializer.

    var serializer = new XMLSerializer();
    serializer.serializeToString(svg); // xml string for `svg` (your node)
    

    Please note that any “Save As” dialogue will depend on the client’s configuration.

    // assuming var `svg` for your SVG node
    var a = document.createElement('a'), xml, ev;
    a.download = 'my_svg.svg'; // file name
    xml = (new XMLSerializer()).serializeToString(svg); // convert node to xml string
    a.href = 'data:application/octet-stream;base64,' + btoa(xml); // create data uri
    // <a> constructed, simulate mouse click on it
    ev = document.createEvent("MouseEvents");
    ev.initMouseEvent("click", true, false, self, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    a.dispatchEvent(ev);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following SVG source code that generates a number of boxes with
I have a SVG file that I want to extend by adding onclick handlers
I have written a small example page that looks like this: <!DOCTYPE html> <html>
I have a svg generated by d3.js like this one: <svg height=1094 width=1254> <g
I have a GWT application that generates SVG files. I want to embed an
I have an SVG that I will add elements to. And on mousemove this
I have a long method in my Model that generates an SVG from the
I have a scatter plot that is generated using D3. Points (SVG circles) on
I have some SVG files that I'd like to create a PDF with. For
I have an SVG slider that I've been working on ... please see it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.