PhantomJS onUrlChanged() 当URL通过导航从当前URL更改时调用该函数。它有一个参数,即回调函数,它是一个新的URL targetUrl 字符串。 语法 其语法如下 – page.onUrlChanged = function(targetUrl) {}JavaScriptCopy 示例 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); });JavaScriptCopy 上述程序将会生成以下 输出 。 Entered onUrlChanged callback: http://localhost/tasks/c.htmlJavaScriptCopy