var webpage = require('webpage').create();
var filename = 'demo.png';
webpage.open('https://www.example.com/', function() {
webpage.render(filename);
phantom.exit();});
在上面的代码中,当示例网站加载时,它会显示一个引导程序弹出窗口。现在在幻影js我想拍一个没有弹出窗口的网页截图。请帮我看看如何通过phantomjs隐藏这个弹出窗口..
答案 0 :(得分:1)
您需要在制作屏幕截图之前隐藏/关闭模式:
var page = require('webpage').create();
var filename = 'demo.png';
page.open('https://www.example.com/', function() {
// Delay script by a second to give
// javascript some time to load and execute modal
setTimeout(function(){
page.evaluate(function(){
// You'll need to find the modal id to hide it programmatically
$('#themodal').modal('hide');
});
page.render(filename);
phantom.exit();
},
1000);
});
另一种方法是从DOM中删除模态窗口元素:
page.evaluate(function(){
// These classes are for Bootstrap 4
$('.modal, modal-backdrop').remove();
});