title: DataURL not returning value
body: <p>I have created a function that stores DataURI of image in local storage.</p>
  
  <p>Data is stored perfectly in the local storage but if I try to get value from function i.e. return statement, then I get "undefined" value.
  Probably, the function is returning value before even converting to dataURL.</p>
  
  <p>Need your help.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>function getImageDataURL(local_name,w,h,i){    
  var data, canvas, ctx;
  var img = new Image();
  img.onload = function(){      
      canvas = document.createElement('canvas');
      canvas.width = w;
      canvas.height = h;
      ctx = canvas.getContext("2d");
      ctx.drawImage(img,0,0,w,h);
      try{
          data = canvas.toDataURL("image/png");
          localStorage.setItem(local_name,data);
      }catch(e){
          console.log("error "+e)
      }
  }
  try{
      img.src = i;
  }catch(e){}
  return data;
  </code></pre>
  
  <p>}</p>