PhantomJS onAlert() 这个回调函数在页面上出现提示框时被调用。回调函数接受一个字符串参数,不返回任何值。 语法 它的语法如下所示− var wpage = require('webpage').create(); wpage.onAlert = function(msg) {};JavaScriptCopy 示例 以下示例展示了 onAlert() 方法的使用。 var wpage = require('webpage').create(); wpage.onAlert = function(str) { console.log(str); } wpage.open('http://localhost/tasks/alert.html', function(status) { //wpage.stop(); console.log(status); phantom.exit(); });JavaScriptCopy 提示.html <html> <head></head> <body> <script type = "text/javascript"> alert("Welcome to phantomjs"); </script> <h1>This is a test page</h1> </body> </html> HTMLCopy 以上程序生成以下 输出 。 Welcome to phantomjs SuccessJavaScriptCopy