Phantomjs-ownspages-property

提供:Dev Guides
移動先:案内検索

PhantomJS-ownsPagesプロパティ

*ownsPages* プロパティは、Webページによって開かれたページがその子ページであるかどうかをチェックします。 したがって、 *true* または *false* を返します。

構文

その構文は次のとおりです-

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

*ownsPages* プロパティの使用を理解するための例を見てみましょう。
var wpage = require('webpage').create();
wpage.open('http://localhost/tasks/page1l', function (status) {
   console.log(wpage.ownsPages);
   phantom.exit();
});

page1l

<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("http://localhost/tasks/al","page1");
         }
      </script>

      <h1>This is a test page</h1>
   </body>

</html>

上記のプログラムは、次の output を生成します。

True