1
在Firefox WebExtension上工作。Firefox/Chrome擴展程序:如何在創建新選項卡時打開鏈接?
下面的代碼在我打開一個新選項卡時工作,但是當我點擊一個鏈接時它正在更新任何當前選項卡。
如何使用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);