+ 1

JavaScript errors

how do you deal with JavaScript errors such as "Cannot read property of null" when using methods such as getContext('2d'), window. innerHeight/Width ?

2nd Jan 2018, 11:48 PM
Mkansi Eddie
Mkansi Eddie - avatar
1 Answer
+ 4
Wait for the document to load before getting the canvas. So something like this: onload = function() { canvas = document.getElementById('myCanvas'); ctx = canvas.getContext('2d'); ..... ... }
3rd Jan 2018, 12:32 AM
The Coding Sloth
The Coding Sloth - avatar