drawImage don't work on chrome extention

Posted by shrwea on Stack Overflow See other posts from Stack Overflow or by shrwea
Published on 2014-08-18T16:18:55Z Indexed on 2014/08/18 16:20 UTC
Read the original article Hit count: 142

I use canvas drawImage in popup.html. But it doesn't work. Please advise me.

popup.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
</head>
<body>
    <canvas id="test"></canvas>
    <script src="test.js"></script>
</body>
</html>

test.js

var image = document.createElement("img");
image.src = "test.png";
image.onload = function(){
    var canvas = document.getElementById('test');
    var ctx = canvas.getContext('2d');
    ctx.drawImage(image, 0, 0);
}

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about google-chrome-extension