- 文件系统模块
- PhantomJS - 属性
- PhantomJS - 方法
- 系统模块
- PhantomJS - 属性
- Web 服务器模块
- PhantomJS - 属性
- PhantomJS - 方法
- 其他
- 命令行界面
- PhantomJS - 屏幕捕捉
- PhantomJS - 页面自动化
- PhantomJS - 网络监控
- PhantomJS - 测试
- PhantomJS - REPL
- PhantomJS - 示例
- PhantomJS 有用资源
- PhantomJS - 快速指南
- PhantomJS - 有用资源
- PhantomJS - 讨论
PhantomJS - onCallback()
**onCallback** 方法用于将值从网页传递到网页对象,并且使用 window.callPhantom() 方法来完成。 此方法在内部调用 onCallback 函数。
语法
其语法如下 −
var wpage = require('webpage').create();
wpage.onCallback = function(data) {}
示例
以下示例演示了 **onCallback()** 方法的使用。
var wpage = require('webpage').create();
wpage.onCallback = function(str) {
console.log(str + " phantomJs");
}
wpage.open('https:///tasks/callback.html', function(status) {
console.log(status);
phantom.exit();
});
callback.html
<html>
<head></head>
<body>
<script type = "text/javascript">
var a = window.callPhantom("Welcome to ");
</script>
</body>
</html>
上述程序生成以下 **输出**。
Welcome to phantomJs Success
phantomjs_webpage_module_events_callbacks.htm
广告