pagecallback.js 609 B

1234567891011121314151617
  1. var p = require("webpage").create();
  2. p.onConsoleMessage = function(msg) { console.log(msg); };
  3. // Calls to "callPhantom" within the page 'p' arrive here
  4. p.onCallback = function(msg) {
  5. console.log("Received by the 'phantom' main context: "+msg);
  6. return "Hello there, I'm coming to you from the 'phantom' context instead";
  7. };
  8. p.evaluate(function() {
  9. // Return-value of the "onCallback" handler arrive here
  10. var callbackResponse = window.callPhantom("Hello, I'm coming to you from the 'page' context");
  11. console.log("Received by the 'page' context: "+callbackResponse);
  12. });
  13. phantom.exit();