+ 2
canvas getContext , onload
I have problem with canvas - method getContext. Code returns error: Can not read property 'getContext' of null. I think that the reson is not full load html document. When I make this code on my laptop I only need to put: <script type = "text / javascript" src = "script.js"> </ script> behind canvas tag but when I copy code to playground sololearn it doesn't work, any easy solution?
9 odpowiedzi
+ 6
sololearn requires a window.onload=function(){
//insert code here
}
ritual.
0
Make sure that js its loaded AFTER html
0
Thanks Brainsng but I thried already that:
window.onload = function(){}
and body onload
leads to lack of access to several functions. In html I have 3 button with onclick that starts functions. When I close this functions in another I lose access.
0
Dawid Post your code if want more help
0
Functions definition aparts, clock its drawed like expected
0
KrOW - Yes, with window.onload, but functions "start","stop","reset" doesnt works.
0
Thanks, Brainsng - I put all on function not only:
window.onload = function(){
var canvas = document.getElementById("canvas");
context = canvas.getContext("2d");
schwimmer1 = 0;
schwimmer2 = 15;
schwimmer3 = 30;
schwimmer4 = 45;
drawClock();
}