Skip to content

Instantly share code, notes, and snippets.

@ariya
Created September 17, 2011 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ariya/1224113 to your computer and use it in GitHub Desktop.
Save ariya/1224113 to your computer and use it in GitHub Desktop.
PhantomJS 1.3 example: prevent window.onload
var page = new WebPage(),
address;
// Let's see what the web page's console might output.
page.onConsoleMessage = function (msg) {
console.log('from web page: ' + msg);
};
// Hijack assignment to window.onload to do nothing.
page.onInitialized = function () {
page.evaluate(function () {
window.__defineSetter__('onload', function (handler) {
});
});
};
if (phantom.args.length === 0) {
console.log('Usage: prevent-onload.js <some URL>');
phantom.exit();
} else {
address = phantom.args[0];
page.open(address, function (status) {
if (status !== 'success') {
console.log('FAIL to load the address');
} else {
console.log('Loading completed.');
}
phantom.exit();
});
}
@thouger
Copy link

thouger commented Nov 13, 2017

i have a question is what is the use of Hijack assignment to window.onload?What can we do?

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