2012-05-12 04:32:16 +04:00
|
|
|
var p = require("webpage").create();
|
|
|
|
|
|
|
|
p.onConsoleMessage = function(msg) { console.log(msg); };
|
|
|
|
|
2012-12-07 00:29:37 +04:00
|
|
|
// Calls to "callPhantom" within the page 'p' arrive here
|
2012-05-12 04:32:16 +04:00
|
|
|
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
|
2012-12-07 00:29:37 +04:00
|
|
|
var callbackResponse = window.callPhantom("Hello, I'm coming to you from the 'page' context");
|
2012-05-12 04:32:16 +04:00
|
|
|
console.log("Received by the 'page' context: "+callbackResponse);
|
|
|
|
});
|
|
|
|
|
|
|
|
phantom.exit();
|