I've tried doing this for a few hours, and I've tried every solution that I could find both on stackoverflow and on other sites, without success.
The most remarkable thing is that every solution is completely or at least distinctly different from one another. And wc3schools and sites like that seem to have no default way of solving this whatsoever.
I have this simple HTML-document with this body:
<body onload="draw();">
<canvas id="canvas1" width="500" height="500"></canvas>
</body>
And this js-document:
// JavaScript Document
function draw() {
var canvas1 = document.getElementById('canvas1');
if(canvas1.getContext) {
var ctx = canvas1.getContext('2d');
//Here's a lot of drawing that I've removed to make everything that's relevant more readable.
}
}
So this is what I'm working with, and as u can see I've removed all of the code drawing on the canvas since that code shouldn't be necessary to know to save the canvas (please tell me if it is, though).
I don't really care what format I'm saving in or how I do it (by clicking on a button I have to implement/by right-clicking on the canvas/other solutions), I just want to know how to do it in the simplest possible way!