PhantomJS pages 属性:获取页面打开的子页面数组


发布日期 : 2021-12-07 07:06:06 UTC

访问量: 9 次浏览

PhantomJS pages 属性

属性 Pages 将给出一个使用 window.open 在一个页面中打开的页面数组。如果页面在您引用的URL中被关闭,则不会被考虑。

语法

pages 语法如下 –

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

示例

让我们以一个示例来理解 page 属性的使用。

var wpage = require('webpage').create();
wpage.open('http://localhost/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("http://localhost/tasks/a.html","page1");
window.open("http://localhost/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 的页面数组。