+ 11

How do I make JS wait untill HTML is fully loaded?

On SoloLearn's code playground: I couldn't control canvas with JS, unless I put whole JS code in inline script. Is there any way that would work with external JS script?

8th Aug 2019, 11:54 AM
cadbrooke
cadbrooke - avatar
5 Respuestas
+ 13
To call js once the window is loaded use: window.onload = function(){ // Some code that is called when the document is loaded }
8th Aug 2019, 12:15 PM
Paul Grasser
Paul Grasser - avatar
+ 11
You can use this too ... <body onload="your_defined_function()"> .......... </body>
9th Aug 2019, 5:59 AM
Prince Raj
Prince Raj - avatar
+ 7
or this in es6: onload = () => { // Some code }
9th Aug 2019, 4:38 PM
InvBoy [ :: FEDE :: ]
InvBoy [ :: FEDE :: ] - avatar
+ 3
window.onload = () => { }
9th Aug 2019, 8:04 PM
Divine Hycenth
Divine Hycenth - avatar
0
$(document).ready(() => {}); if you use JQuery
10th Aug 2019, 9:21 AM
Timur Myngbay
Timur Myngbay - avatar