當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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('http://localhost/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>

上述程序生成以下內容output

Entering in onPageCreated callback
WebPage(name = "WebPage")
Success

相關用法


注:本文由純淨天空篩選整理自 PhantomJS - onPageCreated()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。