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 7071203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:39:34+00:00 2026-05-28T05:39:34+00:00

I am new to SVG and not an advanced user of JavaScript. I have

  • 0

I am new to SVG and not an advanced user of JavaScript. I have a webpage with svg content dynamically rendered by javascript. In Internet Explorer when I right click on the svg content, I get option “Save Picture As” and I am able to save the content as png or svg.

How do I programatically do it by having a button and allow user to save the content in png on to their machine.

  • 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-05-28T05:39:35+00:00Added an answer on May 28, 2026 at 5:39 am

    From my research there is no way to do this without sending the svg content to your server and having it return the data to save as a file download.

    However, even this is tricky to achieve with a single AJAX-style request and the solution is amazingly convoluted. Others have linked to other posts that explain this, but I already went through the same answers and none of them explain it very well.

    Here are the steps that worked for me:

    1. Use JavaScript to serialize the SVG content.

      var svgString = new XMLSerializer().serializeToString(svgElement);

    2. Create a hidden iframe whose src is the submit url. Give it an id.
    3. Create a hidden input. Set the value of this input to the serialized SVG content.
    4. Create a form whose target is the id given to the iframe, and whose action is the submit url. Put the input inside the form.
    5. Submit the form.
    6. On your server, use whatever tools are available (I don’t use .NET so you’re on your own here…) to convert the SVG document to a PNG. Send the PNG content back to the client, making sure to use the headers:

      Content-Type:image/png

      Content-Disposition:attachment; filename=mypng.png

    The browser should initiate a file download on the returned content, although this is browser-dependent and I’m not certain but some browsers may choose to open images in a new tab instead of opening a file download dialog.

    Here is an (imperfect) function that will do the AJAX work (uses JQuery but you should get the idea). data is the serialized SVG:

    function ajaxFileDownload(url, data) {
        var iframeId = "uniqueIFrameId";     // Change this to fit your code
        var iframe = $("#" + iframeId); 
    
        // Remove old iframe if there
        if(iframe) { 
            iframe.remove(); 
        }
    
        // Create new iframe 
        iframe = $('<iframe src=""' + url + '"" name="' + iframeId + '" id="' + iframeId + '"></iframe>')
            .appendTo(document.body)
            .hide(); 
    
        // Create input
        var input = '<input type="hidden" name="data" value="' + encodeURIComponent(data) + '" />'; 
    
        // Create form to send request 
        $('<form action="' + url + '" method="' + 'POST' + '" target="' + iframeId + '">' + input + '</form>')
            .appendTo(document.body)
            .submit()
            .remove();
    }
    

    Note that this URL-encodes the SVG content, so you will have to decode it on your server before converting to PNG.

    Also note that if you have defined styles for your SVG in an external stylesheet, they will not be serialized. I decided to put all styles inline on the elements as presentation attributes for this reason.

    I hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having issues embedding SVG into a webpage. I have found the simplest
I'm new to TypeScript and JavaScript, although not completely new to programming. I wondered
I'm quite new to svg and I have to perform a task with it,
I have a svg file which I am accessing through my javascript. Like this
I have a set of animated Raphael SVG elements. I am adding new elements
Does anybody please have an idea how to center-align the new (i.e. svg-based) Google
Seems I not understand some fundamental in javascript, I have the following code: Raphael.fn.group
So I'm new to D3 and have little exp with JavaScript in general. So
To the esteemed readers. I'm reasonably new in javascript and I have come across
I am new to svg and dont know its structure.I want to create 10

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.