there is an image on my webpage, i have given user option to edit the content on the image and download the image using javascript in codeigniter. the following is the download button code:
<div id="chumma" class="col-md-12">
<button id="download" type="submit" onclick="download_image()" name="button" value="Download" class="btn btn-primary" >Download</button>
</div>
function download_image(){
var canvas = document.getElementById("imageCanvas");
image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
var link = document.createElement('a');
link.download = "<?php echo $val['title']; ?>.png";
link.href = image;
link.click();
}
but this is not downloading the image, instead its just reloading the page, can anyone please tell me what is wrong here, thanks in advance