canvas.toDataURL()无法在Chrome中运行

时间:2015-10-25 06:44:57

标签: javascript google-chrome canvas

我在Firefox中获得了完美的dataURI,但在Chrome中却没有。在Chrome中,它只是原始的空白画布。怎么了? (我需要在页面上生成图像)。

<html>
  <head>
    <script src="jquery-2.1.4.min.js"></script>
    <script src="rasterizeHTML.allinone.js"></script>
  </head>

  <body>
    <button id="run">Run!</button>
    <div id="newcontent">Content example</div>
    <canvas id="canvas" width="800" height="800" ></canvas>

    <script>
    $('#run').click(function(){
      var canvas = document.getElementById("canvas");
      var newcontent = document.getElementById("newcontent").innerHTML;
      console.log(newcontent);
      rasterizeHTML.drawHTML(newcontent, canvas);

      var canvas = document.getElementById("canvas");

      canvas.src = canvas;
      canvas.crossOrigin = 'Anonymous';

      var imgData = canvas.toDataURL();
      console.log(imgData);
    });
    </script>
</body>
</html>

0 个答案:

没有答案