Skip to content

Instantly share code, notes, and snippets.

@ambar
Created June 17, 2011 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ambar/1030979 to your computer and use it in GitHub Desktop.
Save ambar/1030979 to your computer and use it in GitHub Desktop.
如何保持chrome扩展选项tab唯一
// 打开chrome扩展选项tab
var option_url = chrome.extension.getURL('options/index.html');
chrome.tabs.getAllInWindow(null,function(tabs){
var option_tab = tabs.filter(function(t) { return t.url === option_url });
if(option_tab.length){
// 已经打开,直接激活
chrome.tabs.update(option_tab[0].id,{selected:true});
}else{
chrome.tabs.create({url:option_url,selected:true})
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment