MozillaZine

Listening to tab-switching in main window

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

Post Posted December 17th, 2002, 2:49 pm

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

alanjstr
Moderator

User avatar
 
Posts: 9100
Joined: November 5th, 2002, 4:43 pm
Location: Anywhere but here

Post Posted December 17th, 2002, 10:12 pm

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

Post Posted December 18th, 2002, 1:35 am

Can I use that to get Javascript notifications of when the tab is changed though?

alanjstr
Moderator

User avatar
 
Posts: 9100
Joined: November 5th, 2002, 4:43 pm
Location: Anywhere but here

Post Posted December 18th, 2002, 7:07 am

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.

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 3 guests