I need to capture an event which should be triggered just before the content of the iframe disappears.
I have been trying to accomplish something like this
$iframe = $('iframe');
$iframe.beforeunload(function () {
debugger;
});
OR
$iframe = $('iframe');
$iframe.unload(function () {
debugger;
});
I have even tried binding it to the iframe window itself without any luck
$iframe = $('iframe');
$iframe[0].contentWindow.onunload = function () {
debugger;
};
None of these eventhandlers actually trigger for me
and I am quite confused why. To reload the iframe I use .reload()
from outside the iframe and from within, maybe I need to use a different method?
onunload occurs when the user navigates away from the page (by clicking on a link, submitting a form, closing the browser window, etc.). Note: The onunload event is also triggered when a user reloads the page (and the onload event).
onbeforeunload Below are my findings on the iPad; Using window. onunload , I am able to get an alert when user navigates to a different page from myPage. html (either by clicking on some link or doing a Google search while on myPage.
Figured it out! I didn't know the contentWindow
looses its reference after a reload.
$iframe.load(function () {
$iframe[0].contentWindow.onbeforeunload = function () {
debugger;
};
});
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