PhantomJS - ownsPages 屬性



ownsPages 屬性檢查由網頁開啟的頁面是否為子頁面。它會根據情況返回 truefalse

語法

語法如下:

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

示例

舉例說明如何使用 ownsPages 屬性。

var wpage = require('webpage').create(); 
wpage.open('https:///tasks/page1.html', function (status) {
   console.log(wpage.ownsPages);
   phantom.exit();
});

page1.html

<html> 
   <head> 
      <title>Testing PhantomJs</title> 
   </head> 
   
   <body> 
      <script type = "text/javascript"> 
         console.log('welcome to cookie example'); 
         document.cookie = "username = Roy; expires = Thu, 22 Dec 2017 12:00:00 UTC"; 
         
         window.onload =  function() { 
            console.log("page is loaded"); 
            window.open("https:///tasks/a.html","page1");  
         } 
      </script>  
      
      <h1>This is a test page</h1> 
   </body> 
   
</html> 

以上程式會生成以下 輸出

True
phantomjs_webpage_module_properties.htm
廣告
© . All rights reserved.