I have recently upgraded JQuery to version 1.9. On version 1.4, I was doing something like this:
var windowEvents = $(window).data("events");
if (windowEvents.unload.length > 0) {
// some fun stuff
}
Of course, in jQuery 1.8 this ability was removed. After some research, I found a suggestion for getting around this:
var windowEvents = $._data($(window), "events");
But, according to the console, windowEvents is undefined. What am I doing wrong? Any other suggestions?
Thanks in advance :)
Seems to work for me with $._data
if the event handler is bound :
$(window).on('unload', function() {
// do stuff
});
if (($._data( window, 'events' ).unload || []).length) {
console.log('unload is bound');
}else{
console.log('unload is NOT bound');
}
FIDDLE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With