0

I want to know the best option to download an edited image on my computer, kind of the website straightouttasomewhere.com I created the button already which is easy to create, but I want that button make it work.

<button id="dlbtn" onclick="saveAsLocalImg()">Download</button>

then, this is the javascript function I want to use to make the download button work

function saveAsLocalImg(){
    var cvs=document.getElementById("mycanvas");
    var img=cvs.toDataURL("image/png").replace("image/png", "image/octet-stream"); 
    window.location.href=img;
}

This javascript function work?

Btw, I am using notepad++ because of lacking of web design programs.

Any suggestions??? I will appreciate your help

1 Answers1

0

You might want to use HTML5 it's a simple yet a good solution since most browsers nowadays supports it.
Here's an example

<p>Example 1<br>
   <a href="http://dummyimage.com/600x400/000/fff.png" download>Download this image</a></p>

<p>Example 2<br>
   <a href="http://dummyimage.com/600x400/000/fff.png" download="alternate-filename.png"><img
       src="http://dummyimage.com/150x100/000/fff.png"></a></p>

This answer was given by Salman A and it's available here

If you still want to use JavaScript this might be useful http://pastebin.com/8RZB6F2a

This might help you decide what to use http://caniuse.com/#feat=download

Community
  • 1
  • 1
Pedro Cavaleiro
  • 835
  • 7
  • 21