當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PhantomJS onUrlChanged()用法及代碼示例


當使用導航從當前 URL 更改 URL 時調用此方法。它有一個回調參數,即新的 URLtargetUrl細繩。

用法

其語法如下:

page.onUrlChanged = function(targetUrl) {}

示例

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); 
});

上述程序將生成以下內容output

Entered onUrlChanged callback:
http://localhost/tasks/c.html

相關用法


注:本文由純淨天空篩選整理自 PhantomJS - onUrlChanged()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。