Skip to content

Instantly share code, notes, and snippets.

@stechz
Created June 27, 2012 21:50
Show Gist options
  • Save stechz/3007080 to your computer and use it in GitHub Desktop.
Save stechz/3007080 to your computer and use it in GitHub Desktop.
Addon SDK code for removing onbeforeclose alerts.
function contentScript() {
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', 'data:text/javascript,' + escape(
'(' + function() {
onbeforeunload = null;
}.toString() + ')()'));
document.body.appendChild(script);
}
var pagemod = require("page-mod");
pagemod.PageMod({
include: 'https://supyo.hipchat.com/*',
contentScriptWhen: 'end',
contentScript: '(' + contentScript.toString() + ')();'
});
@stechz
Copy link
Author

stechz commented Jun 27, 2012

You may also consider using window.defineProperty() to guarantee that onbeforeunload never gets overwritten.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment