PhantomJS - ownsPages 属性



ownsPages 属性检查由网页打开的页面是否为子页面。它会根据情况返回 truefalse

语法

语法如下:

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

示例

举例说明如何使用 ownsPages 属性。

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

以上程序会生成以下 输出

True
phantomjs_webpage_module_properties.htm
广告