PhantomJS - pages 属性

Pages 属性将为您提供使用 window.open 在页面中打开的页面数组。如果页面在您引用的 URL 中关闭,则不会考虑该页面。

语法

其语法如下 −

var wpage = require('webpage').create();
wpage.pages;

示例

让我们举一个例子来了解 page 属性的用法。

var wpage = require('webpage').create(); 
wpage.open('http://localhost/tasks/ptitle.html', function (status) {  
   console.log(wpage.pages); 
   phantom.exit(); 
});

ptitle.html

<html> 
   <head> 
      <title>Testing PhantomJs</title> 
   </head> 
   
   <body> 
      <script type = "text/javascript"> 
         window.onload = function() { 
            window.open("http://localhost/tasks/a.html","page1"); 
            window.open("http://localhost/tasks/content.html", "page2"); 
         } 
      </script>  
      <h1>This is a test page</h1> 
   </body>
   
</html>

上述程序生成以下输出

WebPage(name = "WebPage"),WebPage(name = "WebPage")

上例中我们引用的网页是 title.html,它有两个 window.open 命令。输出显示了来自 wpage.pages 的页面数组。

phantomjs_webpage_module_properties.html