I have a JavaScript generator which outputs black, grey and white square. How am I able to right click and save image of the generated image on the webpage?
HTML < button onclick="run()">Generate< /button>
function run() {
var x = document.getElementById("block");
if (x) {
x.parentNode.removeChild(x);
}
var rows = 20;
var cols = 20;
var size = 30;
var container = document.createElement("div");
container.id = "block";
for (var i = 0, len = rows * cols; i < len; i++) {
x = document.createElement("div");
x.className = "cell";
x.style.height = size + "px";
x.style.width = size + "px";
x.style.backgroundColor = pickColor();
container.appendChild(x);
}
document.body.appendChild(container);
}
function pickColor(){
var colorArray = ["black", "grey", "white"];
return colorArray[Math.floor(Math.random() * colorArray.length)];
}
window.onload = run;