Remove Chrome tab listeneres (chrome.tabs.onSelectionChanged.removeListener)

1,949 views
Skip to first unread message

Max Air

unread,
Aug 21, 2011, 11:48:50 AM8/21/11
to Chromium-extensions
Hi there

I can't figure out how to remove tab listeners. I have to let the
listener run till a certain moment:

chrome.tabs.onSelectionChanged.addListener(function(tab_id) {
console.log("tab changed" + tab_id);
});


I tried it with

foobar = chrome.tabs.onSelectionChanged.addListener(function(tab_id) {
console.log("tab changed" + tab_id);
});

but foobar is undefined. Anyone got through this?

Best

Boris Smus

unread,
Aug 22, 2011, 10:52:43 AM8/22/11
to Max Air, Chromium-extensions
You need a handle to the listener function itself. Name the function by doing something like 

var listener = function(tab_id) {

   console.log("tab changed" + tab_id);
});

Then manipulate your SelectionChanged listeners:

chrome.tabs.onSelectionChanged.addListener(listener);
// Do stuff that changes selection.
// Unbind the listener.
chrome.tabs.onSelectionChanged.removeListener(listener);

- Boris


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Max Air

unread,
Aug 26, 2011, 4:34:26 PM8/26/11
to Chromium-extensions
Thanks Boris.
> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to
> > chromium-extensions+unsubscr...@chromium.org.
Reply all
Reply to author
Forward
0 new messages