- 檔案系統模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 系統模組
- PhantomJS - 屬性
- Web 伺服器模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 其他
- 命令列介面
- PhantomJS - 螢幕捕獲
- PhantomJS - 頁面自動化
- PhantomJS - 網路監控
- PhantomJS - 測試
- PhantomJS - REPL
- PhantomJS - 範例
- PhantomJS 實用資源
- PhantomJS - 快速指南
- PhantomJS - 實用資源
- PhantomJS - 討論
PhantomJS - onPageCreated()
當頁面開啟新的子視窗時會呼叫此回撥。
語法
其語法如下所述 −
wpage.onPageCreated = function(newPage) {}
範例
以下示例展示如何使用 onPageCreated() 方法。
var wpage = require('webpage').create();
wpage.onPageCreated = function(newpage) {
console.log("Entering in onPageCreated callback");
console.log(newpage.url);
}
wpage.open('https:///tasks/newwindow.html', function(status) {
console.log(status);
});
newwindow.html
<html>
<head>
<title>Welcome to phantomjs</title>
</head>
<body>
<script type = "text/javascript">
window.onload = function() {
window.open("test.html", "window1");
}
</script>
<h1>This is a test page</h1>
</body>
</html>
上述程式會產生以下 輸出。
Entering in onPageCreated callback WebPage(name = "WebPage") Success
phantomjs_webpage_module_events_callbacks.htm
廣告