Phantomjs-onnavigationrequested
提供:Dev Guides
このコールバックは、ナビゲーションイベントがいつ発生するかを通知します。 それは次の4つの引数を取ります-
- URL -ナビゲーションイベントのターゲットURL。
- タイプ-タイプの値は未定義、Linkclicked、FormSubmitted、BackorForward、Reload、FormReSubmitted、その他です。
- willNavigate -ナビゲーションが行われる場合はtrue、ロックされている場合はfalseです。
- メイン-メインウィンドウからの場合はtrue、iframeまたは他のサブフレームからの場合はfalseです。
構文
その構文は次のとおりです-
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/wopen2l', function(status) {
console.log(status);
if (status == success) {
console.log(wpage.content);
wpage.reload();
}
});
上記のプログラムは、次の output を生成します。
Trying to navigate to: http://localhost/tasks/wopen2l
Caused by: Other
Will actually navigate: true
Sent from the page's main frame: true
Success
ページのリロード時にナビゲートコールバックを呼び出しています。