【发布时间】:2016-02-26 06:38:46
【问题描述】:
当我打开一个新标签时,下面的代码可以工作,但是当我点击一个链接时它会更新任何当前标签。
如何使用query仅选择新标签?
有没有其他方法可以做到这一点?
/* Load Google when creates a new tab. */
function openMyPage() {
//console.log("injecting");
chrome.tabs.query({
'currentWindow': true,
'active': true
// This will match all tabs to the pattern we specified
}, function(tab) {
// Go through all tabs that match the URL pattern
for (var i = 0; i < tab.length; i++){
// Update those tabs to point to the new URL
chrome.tabs.update(
tab[i].id, {
'url': 'http://google.com'
}
);
}
});
};
//Add openMyPage() as a listener when new tabs are created
chrome.tabs.onCreated.addListener(openMyPage);
【问题讨论】:
标签: javascript google-chrome firefox google-chrome-extension firefox-addon-webextensions