Files
phantomjs/examples/pagecallback.js
T
Ivan De Marino caf13651b7 Adding "window.phantomCallback()" within the page context.
The callback is harmless: if the user registers a "page.onCallback = [Function]",
that will receive any JS type passed via "phantomCallback()".
Also, if the handler for ".onCallback" returns a value, that is passed back as a
return value of "phantomCallback()".

Also, added "page.onConfirm" and "page.onPrompt".
This solves [Issue #133](http://code.google.com/p/phantomjs/issues/detail?id=133).
2012-06-14 23:29:13 -07:00

18 lines
606 B
JavaScript

var p = require("webpage").create();
p.onConsoleMessage = function(msg) { console.log(msg); };
// Calls to "phantomCallback" within the page 'p' arrive here
p.onCallback = function(msg) {
console.log("Received by the 'phantom' main context: "+msg);
return "Hello there, I'm coming to you from the 'phantom' context instead";
};
p.evaluate(function() {
// Return-value of the "onCallback" handler arrive here
var callbackResponse = callPhantom("Hello, I'm coming to you from the 'page' context");
console.log("Received by the 'page' context: "+callbackResponse);
});
phantom.exit();