我怎么知道一个标签页是从另一个标签页的页面链接还是内容脚本打开的?
而且如果可以的话,我也需要那个标签页的信息。
chrome.tabs.onCreated.addListener(function(id, info, tab){
// tab doesn't contain any such info
});
我怎么知道一个标签页是从另一个标签页的页面链接还是内容脚本打开的?
而且如果可以的话,我也需要那个标签页的信息。
chrome.tabs.onCreated.addListener(function(id, info, tab){
// tab doesn't contain any such info
});
chrome.tabs.onCreated.addListener(function(tab){
// You now have things like tab.id exposed
// If you have "tabs" permission, also things like tab.url
// You also have tab.openerTabId for "referrer" tab
// If you have host permissions for the tab:
chrome.tabs.executeScript(
tab.id,
{ code: "document.referrer;" },
function(result) {
// Here, you have the "real" referrer,
// which would be empty for tabs opened via `chrome.tabs`
}
);
});
openerTabId
设置为在打开新标签页之前处于活动状态的标签页。测试这个理论应该很容易。 - Xan