Skip to content

Saving the cosmograph as an image? #65

Answered by Javingka
ymerouani asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @matriim

Try this:

In your html code, include a button you will use to take the screenshot and download the image

    <div  id="download">Download Image</div>

and in your javascript code create a function to manage the download whenever the button is clicked.

var downloadButton = document.getElementById("download");
function download() {
    let canvas = document.getElementById('your-canvas-id'); // replace 'your-canvas-id' with the id of your canvas
    let screenshot = canvas.toDataURL("image/png");
    let a = document.createElement('a');
    a.href = screenshot;
    a.download = 'screenshot.png';
    a.click();
}
downloadButton.addEventListener("click", download);

This will do the …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by rokotyan
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants