PhantomJS ownsPages 属性:检查页面是否打开子页面


发布日期 : 2021-06-05 07:52:13 UTC

访问量: 9 次浏览

PhantomJS ownsPages 属性

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

语法

ownsPages 语法如下:

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

示例

让我们来举个示例来理解 ownsPages 属性的使用。

var wpage = require('webpage').create();
wpage.open('http://localhost/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("http://localhost/tasks/a.html","page1");
}
</script>

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

</html>

上述程序生成以下输出。

True