PhantomJS - onCallback()



**onCallback** 方法用於將值從網頁傳遞到網頁物件,並且使用 window.callPhantom() 方法來完成。 此方法在內部呼叫 onCallback 函式。

語法

其語法如下 −

var wpage = require('webpage').create(); 
wpage.onCallback = function(data) {} 

示例

以下示例演示了 **onCallback()** 方法的使用。

var wpage = require('webpage').create(); 
wpage.onCallback = function(str) { 
   console.log(str + " phantomJs"); 
} 
wpage.open('https:///tasks/callback.html', function(status) { 
   console.log(status);  
   phantom.exit(); 
}); 

callback.html

<html> 
   <head></head> 
   <body> 
      <script type = "text/javascript"> 
         var a = window.callPhantom("Welcome to "); 
      </script> 
   </body> 
</html> 

上述程式生成以下 **輸出**。

Welcome to phantomJs 
Success 
phantomjs_webpage_module_events_callbacks.htm
廣告
© . All rights reserved.