Let say I have two pages. One of them contains another one inside as iframe. If you subscribe to onbeforeunload event on the parent page, then this event doesn\'t triggers if yo
the below code will work across all the browsers
if (typeof window.addEventListener != 'undefined') {
window.addEventListener('beforeunload', test, false);
}
else if (typeof document.addEventListener != 'undefined') {
document.addEventListener('beforeunload', test, false);
}
else if (typeof window.attachEvent != 'undefined') {
window.attachEvent('onbeforeunload', test);
}
else {
if (typeof window.onbeforeunload == 'function') {
window.onbeforeunload = function() {
test();
};
}
else {
window.onbeforeunload = test;
}
}
function test(){ alert('working');}
try this once ...