當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PhantomJS onConsoleMessage()用法及代碼示例


當網頁中有使用控製台消息時使用此回調。此回調采用以下三個參數。

  • Message
  • 行號
  • 源標識符

用法

其語法如下:

page.onConsoleMessage = function(msg, lineNum, sourceId) {}; 

示例

var wpage = require('webpage').create(); 
wpage.onConsoleMessage = function(msg) { 
   console.log('CONSOLE Message:' + msg ); 
}; 
wpage.open('http://localhost/tasks/test.html', function(status) { 
   var script1 = "function(){ console.log('hello world');}"; 
   var value = wpage.evaluate(script1); 
   phantom.exit(); 
});

上述程序生成以下內容output

CONSOLE Message:hello world 

相關用法


注:本文由純淨天空篩選整理自 PhantomJS - onConsoleMessage()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。