我们如何获取当前chrome标签的父标签URL? [英] How do we get the parent tab URL of the current chrome tab?
本文介绍了我们如何获取当前chrome标签的父标签URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序主页上,有一个链接,当单击该链接时会打开一个新选项卡.
On my application home page, there is a link which opens a new tab when clicked.
经过研究,我发现下面的代码在启动新的chrome标签页时触发.下面的"active_tab"对象提供了有关当前标签的信息.
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.
但是,我们如何在此处获取父级"标签的网址(之前的活动标签)?请帮忙.
我需要在此处获取启动此active_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 */
});
});
推荐答案
感谢@wOxxOm.
使用openerTabId属性获取父标签.
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);
});
});
});
这篇关于我们如何获取当前chrome标签的父标签URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文