- PhantomJST 教程
- PhantomJS - 首页
- PhantomJS - 概览
- PhantomJS - 环境设置
- PhantomJS - 对象
- PhantomJS - 方法
- 文件系统模块
- PhantomJS - 属性
- PhantomJS - 方法
- 系统模块
- PhantomJS - 属性
- Web 服务模块
- PhantomJS - 属性
- PhantomJS - 方法
- 其他
- 命令行界面
- PhantomJS - 屏幕截图
- PhantomJS - 页面自动化
- PhantomJS - 网络监控
- PhantomJS - 测试
- PhantomJS - REPL
- PhantomJS - 示例
- PhantomJS 有用资源
- PhantomJS - 快速指南
- PhantomJS - 有用资源
- PhantomJS - 讨论
PhantomJS - onAlert()
当页面上有提示时,将调用此回调。该回调采用一个字符串,不会返回任何内容。
语法
其语法如下:
var wpage = require('webpage').create();
wpage.onAlert = function(msg) {};
示例
以下示例展示了如何使用 onAlert() 方法。
var wpage = require('webpage').create();
wpage.onAlert = function(str) {
console.log(str);
}
wpage.open('https:///tasks/alert.html', function(status) {
//wpage.stop();
console.log(status);
phantom.exit();
});
alert.html
<html>
<head></head>
<body>
<script type = "text/javascript">
alert("Welcome to phantomjs");
</script>
<h1>This is a test page</h1>
</body>
</html>
上述程序生成了以下 输出。
Welcome to phantomjs Success
phantomjs_webpage_module_events_callbacks.htm
广告