0

I am trying to make a download link for picture, everything works if i draw some stuff on canvas like background and text or leave empty, but if i draw image, dataToUrl do not generate a link. Code (shorten version, just to check if toDataUrl works:

$("#butt6").click(function() {
        var c = document.getElementById("PictureBIG");
        var ctx = c.getContext("2d");
        var img = document.getElementById("big1");
        ctx.drawImage(img, 0, 0, 900, 450);
        img.onload = function() {
            var dataUrl =  c.toDataURL('image/jpeg');
        }
        alert(dataUrl);
    });    

It doesnt alert anything at all.

Vytautas
  • 23
  • 6
  • possible duplicate of [Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference](http://stackoverflow.com/questions/23667086/why-is-my-variable-unaltered-after-i-modify-it-inside-of-a-function-asynchron) – Scimonster Nov 22 '14 at 22:09
  • JavaScript is case sensitive, so`onLoad` is not `onload`. Also, use jQuery if you've included the Library. – StackSlave Nov 22 '14 at 22:10
  • any other advices? <: – Vytautas Nov 22 '14 at 22:49

0 Answers0