- 文件系统模块
- PhantomJS - 属性
- PhantomJS - 方法
- 系统模块
- PhantomJS - 属性
- Web 服务器模块
- PhantomJS - 属性
- PhantomJS - 方法
- 其他内容
- 命令行界面
- PhantomJS - 屏幕截图
- PhantomJS - 页面自动化
- PhantomJS - 网络监控
- PhantomJS - 测试
- PhantomJS - REPL
- PhantomJS - 示例
- PhantomJS 有用资源
- PhantomJS - 快速指南
- PhantomJS - 有用的资源
- PhantomJS - 讨论
PhantomJS - onPrompt()
当网页调用提示时,将调用此回调。它需要两个参数,message 和 answer。返回值是字符串。
语法
其语法如下 -
wpage.onPrompt = function(msg, defaultVal) {}
示例
以下代码显示了 onPrompt() 方法的使用。
var wpage = require('webpage').create();
wpage.onPrompt = function(msg, answer) {
console.log("Entering in onPrompt callback");
console.log(msg);
return answer;
}
wpage.open('https:///tasks/prompt.html', function(status) {
console.log(status);
});
prompt.html
<html>
<head>
<title>Welcome to phantomjs</title>
</head>
<body>
<script type = "text/javascript">
window.onload = function() {
prompt("Is the page loaded", "");
}
</script>
<h1>This is a test page</h1>
</body>
</html>
以上程序生成以下输出。
Entering in onPrompt callback Is the page loaded Success
phantomjs_webpage_module_events_callbacks.htm
广告