How do we get the parent tab URL of the current chrome tab?

让人想犯罪 __ 提交于 2019-12-13 17:51:54

问题


On my application home page, there is a link which opens a new tab when clicked.

After some research, I found below code which gets triggered when a new chrome tab is launched. The "active_tab" object below gives information about the current tab.

But how do we get the Parent tab URL (previous active tab) here ? Please help.
I need to get my Home page url here from which this active_tab is launched.

chrome.tabs.onActivated.addListener(function(activeInfo) {  
  chrome.tabs.get(activeInfo.tabId, function(active_tab){

      alert(active_tab.url);          

      /* code */

   });
});

回答1:


Thanks @wOxxOm.

Used the openerTabId property to get parent tab.

chrome.tabs.onActivated.addListener(function(activeInfo) {  
    chrome.tabs.get(activeInfo.tabId, function(active_tab){
        chrome.tabs.get(active_tab.openerTabId, function(parent_tab){             
            alert(parent_tab.url);            
        });     
    });
});


来源:https://stackoverflow.com/questions/43990584/how-do-we-get-the-parent-tab-url-of-the-current-chrome-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!