- PhantomJS Tutorial
- PhantomJS - Home
- PhantomJS - Overview
- PhantomJS - Environment Setup
- PhantomJS - Object
- PhantomJS - Methods
- WebPage Module
- PhantomJS - Properties
- PhantomJS - Methods
- PhantomJS - Events/Callbacks
- PhantomJS - Child Process Module
- File System Module
- PhantomJS - Properties
- PhantomJS - Methods
- System Module
- PhantomJS - Properties
- Web Server Module
- PhantomJS - Properties
- PhantomJS - Methods
- Miscellaneous
- Command Line Interface
- PhantomJS - Screen Capture
- PhantomJS - Page Automation
- PhantomJS - Network Monitoring
- PhantomJS - Testing
- PhantomJS - REPL
- PhantomJS - Examples
- PhantomJS Useful Resources
- PhantomJS - Quick Guide
- PhantomJS - Useful Resources
- PhantomJS - Discussion
PhantomJS - onNavigationRequested()
This callback tells when the navigation event is taking place. It takes the following four arguments −
URL − The target URL of the navigation event.
Type − Values for type are undefined, Linkclicked, FormSubmitted, BackorForward, Reload, FormReSubmitted, Other.
willNavigate − It is true, if navigation will take place, false if it is locked.
Main − It is true, if it comes from main window, false if it comes from iframe or any other sub frame.
Syntax
Its syntax is as follows −
wpage.onNavigationRequested = function(url, type, willNavigate, main) {}
Example
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(); } });
The above program generates the following output.
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
We are invoking the navigate callback on the reload of the page.
phantomjs_webpage_module_events_callbacks.htm
Advertisements
To Continue Learning Please Login
Login with Google