开发者

Determine if javascript has completed

开发者 https://www.devze.com 2023-01-03 00:38 出处:网络
My question is somewhat similar to this one. We want to know if there\'s a way to determine if all javascript has completed (so no javascript is running). We have a lot of stuff that runs on a timeout

My question is somewhat similar to this one. We want to know if there's a way to determine if all javascript has completed (so no javascript is running). We have a lot of stuff that runs on a timeout after the page's onload event, so even after the page is loading, stuff could be happening for a few seconds. For a whole bunch of reasons, mostly relating to requirements from management, we need to know when all of 开发者_如何学Pythonthese scripts have finished running. There's an arbitrary number of them so a general solution would be great.


The quickest and easiest was I can think of is to create a series of boolean values that tell you which processes have finished. After a method finishes, have it set one of the variables to true. When they are all true, you know that it's finished loading.


You could create an excuteWithNotify(functionToEexcute) function. It will receive the function to execute as a parameter, execute it and then it will set the flags appropriately.


I would put all the JS files into one file. Then use the boolean method at the end.


Maybe have those other scripts call an imDone() function when they complete.

0

精彩评论

暂无评论...
验证码 换一张
取 消