PhantomJS - onConfirm()



當頁面中呼叫帶 ok /cancel 的確認資訊時,將呼叫此回撥。其對回撥的返回值為 true 或 false,true 對應於確認框中單擊的 ok,false 對應於單擊的 cancel

語法

其語法如下:

wpage.onConfirm = function(msg) {}; 

示例

以下示例顯示了 onConfirm() 方法的使用。

var wpage = require('webpage').create(); 
wpage.onConfirm = function(msg) { 
   console.log(msg); 
}  
wpage.open('https:///tasks/confirn.html', function(status) { 
   console.log(status); 
   phantom.exit(); 
});

confirm.html

<html> 
   <body> 
      <script> 
         window.confirmationValue = confirm("Press a button!"); 
      </script> 
   </body> 
</html>

上述程式生成以下 輸出

Press a button! 
Success 
phantomjs_webpage_module_events_callbacks.htm
廣告
© . All rights reserved.