Home >Web Front-end >JS Tutorial >How to judge when js script is loaded_javascript skills
In the requirement of "on-demand loading", we often judge that when the script is loaded, a callback function is returned. So how to judge that the script is loaded?
We can use onload to determine the loaded JS object (js.onload). This method is well supported by Firefox2, Firefox3, Safari3.1, and Opera9.6 browsers, but is not supported by IE6 and IE7. Curve to save the country - IE6, IE7 We can use js.onreadystatechange to track each state change (generally loading, loaded, interactive, complete). When the return status is loaded or complete, it means that the loading is completed and the callback function is returned. .
An additional explanation is needed for the readyState state:
1. In the interactive state, users can participate in interactions.
2. Opera actually supports js.onreadystatechange, but its state is very different from that of IE.