I’m putting the following inside my Backbone Main View’s initialize section:
$(window).load(function() {
console.log('Page Loaded');
});
$(window).unload(function() {
console.log('Page Unloaded');
});
Page Unloaded will be displayed on Unload event properly however
Page Loaded never shows up. Changing the bit of code into the following works:
$(function() {
console.log('Page Loaded');
});
But I need $(window).load(). Any idea on why and how?
$(fn)is shorthand for$(document).ready(fn), which isn’t the same as$(window).load(fn).Perhaps window’s onload has already fired when you bind this event? This isn’t a problem with document ready because jQuery has some special handling to run it immediately if it already happened.