If you want an event to work on your page, you should call it inside the $(document).ready() function. Everything inside it will load as soon as the D
Edit: This code will wait until all content (images and scripts) are fully loaded and rendered in the browser.
I've had this problem where $(window).on('load',function(){ ... })
would fire too quick for my code since the Javascript I used was for formatting purposes and hiding elements. The elements where hidden too soon and where left with a height of 0.
I now use $(window).on('pageshow',function(){ //code here });
and it fires at the time I need.
Following
$(document).ready(function() {
});
can be replaced
$(window).bind("load", function() {
// insert your code here
});
There is once more way which i'm using to increase the page load time.
$(document).ready(function() {
$(window).load(function() {
//insert all your ajax callback code here.
//Which will run only after page is fully loaded in background.
});
});