【问题标题】:Setting browserAction icon in a concrete Chrome window在具体的 Chrome 窗口中设置 browserAction 图标
【发布时间】:2013-02-12 00:30:04
【问题描述】:
【问题讨论】:
标签:
windows
google-chrome
google-chrome-extension
icons
browser-action
【解决方案1】:
这是我的解决方案,希望对你有所帮助:
function setIcon(state, getIconNameCallback) {
// we need to set the icon globally first,
// to avoid blinking to default icon
chrome.windows.getLastFocused(null, function(window) {
chrome.tabs.getSelected(null, function(tab) {
chrome.browserAction.setIcon({
'path': getIconNameCallback(state, tab.url)
});
});
});
// then we must set the icon for each tab,
// without that the extension wont behave
// properly with multiple windows
chrome.tabs.query({}, function(tabs) {
for (var i = 0; i < tabs.length; i++) {
chrome.browserAction.setIcon({
'path': getIconNameCallback(state, tabs[i].url),
'tabId': tabs[i].id
});
}
});
}