PhantomJS - Pages 屬性



**Pages** 屬性將為您提供一個在頁面中使用 window.open 開啟的頁面陣列。如果您所引用的 URL 中的頁面已關閉,則不會考慮此頁面。

語法

其語法如下 −

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

示例

讓我們舉個例子來理解 **page** 屬性的使用。

var wpage = require('webpage').create(); 
wpage.open('https:///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("https:///tasks/a.html","page1"); 
            window.open("https:///tasks/content.html", "page2"); 
         } 
      </script>  
      <h1>This is a test page</h1> 
   </body>
   
</html>

以上程式會生成以下 **輸出**。

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

我們在上面的示例中引用的網頁,即 **ptitle.html** 有兩個 window.open 命令。輸出顯示了來自 **wpage.pages** 的頁面陣列。

phantomjs_webpage_module_properties.htm
廣告
© . All rights reserved.