访问量: 10 次浏览
onNavigationRequested()此回调函数在导航事件发生时调用。它接受以下四个参数−
其语法如下−
wpage.onNavigationRequested = function(url, type, willNavigate, main) {}
var wpage = require('webpage').create();
wpage.onNavigationRequested = function(url, type, willNavigate, main) {
console.log('Trying to navigate to: ' + url);
console.log('Caused by: ' + type);
console.log('Will actually navigate: ' + willNavigate);
console.log('Sent from the page\'s main frame: ' + main);
}
wpage.open('http://localhost/tasks/wopen2.html', function(status) {
console.log(status);
if (status == success) {
console.log(wpage.content);
wpage.reload();
}
});
上面的程序会生成以下输出。
Trying to navigate to: http://localhost/tasks/wopen2.html
Caused by: Other
Will actually navigate: true
Sent from the page's main frame: true
Success
在页面重新加载时,我们调用了导航回调函数。