Skip to content

Instantly share code, notes, and snippets.

@enriquez
Created August 3, 2010 13:17
Show Gist options
  • Save enriquez/506351 to your computer and use it in GitHub Desktop.
Save enriquez/506351 to your computer and use it in GitHub Desktop.
if (window.___dialogEncountered === undefined) {
window.___dialogEncountered = false;
}
if (window.___dialogReturnValue === undefined) {
window.___dialogReturnValue = false;
}
window.___dialogHandler = function(dialogType) {
window.parent.___dialogEncountered = dialogType;
return window.parent.___dialogReturnValue;
};
window.alert = function() { return window.___dialogHandler('alert') };
window.confirm = function() { return window.___dialogHandler('confirm') };
window.prompt = function() { return window.___dialogHandler('prompt') };
window.onbeforeunload = function() {}; // returning anything from this function causes popup
// handle frames
for (var i=0; i < window.frames.length; i++) {
try {
window.frames[i].alert = function() { return window.parent.___dialogHandler('alert') };
window.frames[i].confirm = function() { return window.parent.___dialogHandler('confirm') };
window.frames[i].prompt = function() { return window.parent.___dialogHandler('prompt') };
window.frames[i].onbeforeunload = function() {};
} catch(e) {
// frame src is most likely from a different domain
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment