PhantomJS - onConfirm()



This callback is called when there is a confirmed message called with ok /cancel from the page. Its return value to the callback is true or false, which is true for ok and false for cancel clicked on the confirm box.

Syntax

Its syntax is as follows −

wpage.onConfirm = function(msg) {}; 

Example

The following example shows the use of onConfirm() method.

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

confirm.html

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

The above program generates the following output.

Press a button! 
Success 
phantomjs_webpage_module_events_callbacks.htm
Advertisements