PhantomJS - onUrlChanged()



This is called when the URL changes from the current one using navigation. It has one argument to the callback, which is the new URL targetUrl string.

Syntax

Its syntax is as follows −

page.onUrlChanged = function(targetUrl) {}

Example

var wpage = require('webpage').create(); 
wpage.onUrlChanged = function(targeturl) {
   console.log("Entered onUrlChanged callback:"); 
   console.log(targeturl); 
} 
wpage.settings.resourceTimeout = '3'; 
wpage.open('http://localhost/tasks/request.html', function(status) { 
   var Content = '<html><body><div>Test div</div></body></html>'; 
   var pageurl = 'http://localhost/tasks/c.html'; 
   wpage.setContent(Content, pageurl); 
}); 

The above program will generate the following output.

Entered onUrlChanged callback: 
http://localhost/tasks/c.html
phantomjs_webpage_module_events_callbacks.htm
Advertisements