As part of a Mozilla extension, I want to observe changes to the currently-viewed URL in the main browser window. This would include changing URLs by navigation (like the What's Related panel), but also changes by switching between tabs.
I have added an event listener to the tabbrowser:
var tabs = document.getElementById("content");
if (tabs) {
tabs.addEventListener ("select", AnnozillaTabBrowserListener, false);
}
var AnnozillaTabBrowserListener = {
handleEvent: function (evt) {
if (evt.type == "select") {
window.alert (evt.target.mCurrentBrowser.currentURI.spec);
}
}
This more or less works, but when I switch between tabs, I get one "select" event for the tab being deselected, and one "select" event for the tab being switched to, and I can't seem to tell the difference between them.
Does anyone know if I can distinguish between the two events? Or if there is an alternative way of doing this?
Matthew
Listening to tab-switching in main window
-
- Posts: 140
- Joined: December 17th, 2002, 2:43 pm
- alanjstr
- Moderator
- Posts: 9100
- Joined: November 5th, 2002, 4:43 pm
- Location: Anywhere but here
- Contact:
-
- Posts: 140
- Joined: December 17th, 2002, 2:43 pm
Listening to tab-switching in main window
Can I use that to get Javascript notifications of when the tab is changed though?
- alanjstr
- Moderator
- Posts: 9100
- Joined: November 5th, 2002, 4:43 pm
- Location: Anywhere but here
- Contact:
Re: Listening to tab-switching in main window
mjwilson wrote:Can I use that to get Javascript notifications of when the tab is changed though?
Check out Piro's Tabbed Browser Extension. I'm pretty sure he's got listeners in there.