I need some help with my problem; it seems like Chrome doesn't like to run this code, but on Firefox it works:
function createContext(width, height) {
var canvas = document.createElement('canvas');
canvas.id = "1";
canvas.width = width;
canvas.height = height;
document.body.appendChild(canvas);
return canvas.getContext('2d');
}