我想在Firefox中更改标签后获取当前的URL。有可能吗?
答案 0 :(得分:5)
每次选择新标签时,将当前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);