[英]Get current url when changing tabs in xul in firefox
我正在嘗試在Firefox中更改選項卡后獲取當前URL。 可能嗎?
一個完整的示例,每次選擇一個新選項卡時,會將當前URL記錄到錯誤控制台:
function LOG(msg) {
var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService);
consoleService.logStringMessage(msg);
}
function onTabChange() {
var href = gBrowser.contentDocument.location.href;
LOG(href);
}
window.addEventListener("load", function(e) {
gBrowser.tabContainer.addEventListener("TabSelect", onTabChange, false);
}, false);
window.addEventListener("unload", function(e) {
gBrowser.tabContainer.removeEventListener("TabSelect", onTabChange, false);
}, false);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.