Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
REMitchell
GitHub Repository: REMitchell/python-crawling
Path: blob/master/6-Selenium/phantomjs/examples/pagecallback.js
164 views
1
var p = require("webpage").create();
2
3
p.onConsoleMessage = function(msg) { console.log(msg); };
4
5
// Calls to "callPhantom" within the page 'p' arrive here
6
p.onCallback = function(msg) {
7
console.log("Received by the 'phantom' main context: "+msg);
8
return "Hello there, I'm coming to you from the 'phantom' context instead";
9
};
10
11
p.evaluate(function() {
12
// Return-value of the "onCallback" handler arrive here
13
var callbackResponse = window.callPhantom("Hello, I'm coming to you from the 'page' context");
14
console.log("Received by the 'page' context: "+callbackResponse);
15
});
16
17
phantom.exit();
18
19