title: storing base64 in localstorage
body: <p>Well i have a function in javascript:</p>
  
  <pre><code>function store_data(){
  var img=document.createElement("img"); 
  /*var img=new Image();
  img.onload = function() {
      context.drawImage(img, 0, 0);
  };*/
  img.src= URL; //js global var
  var height=parseInt(img.naturalHeight,10);
  var width=parseInt(img.naturalWidth,10);
  var canvas = document.getElementById('myCanvas'); 
  canvas.setAttribute("width", width);
  canvas.setAttribute("height", height);
  
  var context = canvas.getContext('2d');
  context.drawImage(img,0,0);
  canvas.style.width="100%"; 
  var data=(canvas.toDataURL("image/png"));
  localStorage.setItem("data", data);
  
  }
  </code></pre>
  
  <p>The first time when is called store a string like "data;" in localStorage is incomplete the image is like a "data64;aotehtahotetav...". But when i call for second time the data is stored fine. Why happens that? </p>
  
  <p>Perhaps i should load the image in a img of the dom loaded? The image is stored for using in draw late. </p>