Listening to tab-switching in main window

Talk about add-ons and extension development.
Post Reply
mjwilson
Posts: 140
Joined: December 17th, 2002, 2:43 pm

Listening to tab-switching in main window

Post by mjwilson »

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
User avatar
alanjstr
Moderator
Posts: 9100
Joined: November 5th, 2002, 4:43 pm
Location: Anywhere but here
Contact:

Post by alanjstr »

Isn't there already a listener? There's CSS for it.

tab[selected="true"] {
font-weight: bold !important;
}
mjwilson
Posts: 140
Joined: December 17th, 2002, 2:43 pm

Listening to tab-switching in main window

Post by mjwilson »

Can I use that to get Javascript notifications of when the tab is changed though?
User avatar
alanjstr
Moderator
Posts: 9100
Joined: November 5th, 2002, 4:43 pm
Location: Anywhere but here
Contact:

Re: Listening to tab-switching in main window

Post by alanjstr »

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.
Post Reply