When a page is finished loading. Then I want to load a module other, smaller, inside it using jQuery. What should I do?
+2
A:
If you want to wait for the every asset to finish loading, then do something like this:
$(window).load(function(){
$.getScript('/path/to/file.js');
});
You can also use an optional callback method:
$(window).load(function(){
$.getScript('/path/to/file.js', function(){
//Called when script is loaded
});
});
Just to be clear, $(window).load()
fires when everything on the page has finished loading including other scripts and images. $(document).ready()
fires as soon as the DOM can be manipulated, which is often much sooner than $(window).load()
.
Doug Neiner
2009-12-12 03:27:27
This is the `$(document).ready()` event function and is called when the DOM is ready to be manipulated, not when the page has finished loading per se.
Doug Neiner
2009-12-12 03:33:25