- 檔案系統模組
- 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
廣告