Lorin Lorin - 3 years ago 229
Javascript Question

Chrome extension: Get last used tab

I'm trying to create a simple plugin for Google Chrome. One of the functions would be a return to the last used tab, but I don't know how to do it.

So, is there any way to get the last used tab?

Answer Source

You could try adding a hook into the onSelected event of the tabs and just saving that variable... soemthing like this:

var curTabID = 0;
var curWinID = 0;

chrome.tabs.onSelectionChanged.addListener(function(tabId, selectInfo) {
   curTabID = tabId;
   curWinID = selectInfo.windowId;

Then you have the window id and the tab id at all times.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download