I have a function called in popup.html that creates a tab, inserts a mailto to trigger a local (or gmail) mail event. It's my desire for it to then close itself. I've tried numerous things, but it seems like I need something that does the equivalent of:
tabId = chrome.tabs.query(I DON'T KNOW!);
chrome.tabs.remove(tabId);
here's the current code:
var query = { active: true, currentWindow: true };
function callback(tabs) {
var currentTab = tabs[0];
console.log(currentTab);
}
chrome.tabs.remove(chrome.tabs.query(query, callback));
but it's not working.
if useful, here's how I create the tab (which does work as desired):
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
getTabs(tabs, function(full_mail_link){
chrome.tabs.create({ url: full_mail_link });
});
});
any help would be greatly appreciated!
I have a function called in popup.html that creates a tab, inserts a mailto to trigger a local (or gmail) mail event. It's my desire for it to then close itself. I've tried numerous things, but it seems like I need something that does the equivalent of:
tabId = chrome.tabs.query(I DON'T KNOW!);
chrome.tabs.remove(tabId);
here's the current code:
var query = { active: true, currentWindow: true };
function callback(tabs) {
var currentTab = tabs[0];
console.log(currentTab);
}
chrome.tabs.remove(chrome.tabs.query(query, callback));
but it's not working.
if useful, here's how I create the tab (which does work as desired):
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
getTabs(tabs, function(full_mail_link){
chrome.tabs.create({ url: full_mail_link });
});
});
any help would be greatly appreciated!
Share Improve this question asked Dec 19, 2014 at 22:25 Jeremy ToemanJeremy Toeman 811 gold badge1 silver badge7 bronze badges 1- Close iself = close the popup? Close the tab you opened? Both? – Xan Commented Dec 20, 2014 at 12:04
3 Answers
Reset to default 8I don't know what your getTabs function does. Yet if you know how to find the tab id of the tab you want all you need to do is
chrome.tabs.remove(tabId, optionalCallback);
this must be work:
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.remove(tab.id);
});
This should work:
//create the tab
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
getTabs(tabs, function(full_mail_link){
chrome.tabs.create({ url: full_mail_link }, callBackOnCreate);
});
});
function callBackOnCreate(tab)
{
globalCreatedTab = tab.id;
}
chrome.tabs.query({'active': true}, function(tabs) {
for (var i = 0; i < tabs.length; ++i)
{
if (tabs[i].id === globalCreatedTab)
{
chrome.tabs.remove(tabs[i].id, [optional callback]);
}
}
});
Solution: use the query function with the callback and execute the remove function in the callback.
It looks like normal window.open
and window.close()
should also work,
The tab-id is an integer or an array containing integers.