是否可以确定Google Chrome扩展程序中的选项卡的开启者? [英] Is it possible to determine a tab's opener within a Google Chrome extension?

查看:125
本文介绍了是否可以确定Google Chrome扩展程序中的选项卡的开启者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我查看了Tab的文档,但是,似乎没有任何东西可以产生这些信息。 http://code.google.com/chrome/extensions/tabs.html



我已经尝试将这个内容脚本注入到页面中(以为我可以将值传递给我的背景页面):

 警报(window.opener); 

..但它只是产生空值。



<到目前为止,我提出的最好的事情是跟踪当前关注的选项卡,并且每当创建新选项卡时,只需假定重点选项卡是新选项卡的开启者/父代。我相信这会事实上在大多数情况下正确识别父标签,因为背景标签很少(允许)打开新页面。然而,有时候它看起来很糟糕,并且可能不准确 - 例如,如果另一个扩展打开了一个新选项卡,则此方法可能会错误地标识新选项卡的开启者。 解决方案更新:现在可以使用新增的webNavigation API,特别是通过挂钩onCreatedNavigationTarget事件,可靠地自行确定Chrome扩展程序中的选项卡的开启者选项卡。

https:// code.google.com/chrome/extensions/trunk/webNavigation.html


I am looking for a way to determine a given tab's opener (parent tab) within a Google Chrome extension.

I've looked at the documention for Tab but there doesn't really seem to be anything that would yield this information. http://code.google.com/chrome/extensions/tabs.html

I've tried injecting this content script into pages (thinking I could pass the value to my background page):

alert(window.opener);

.. but it just yields null.

The best thing I've come up with so far is to keep track of the currently focused tab, and whenever a new tab is created, just assume that the focused tab is the opener/parent of the new tab. I believe this would de facto identify the parent tab correctly most of the time since background tabs rarely (are allowed to) open new pages. However, it seems kludgey and potentially inaccurate at times -- for example, if another extension opened a new tab, this method may misidentify the new tab's opener.

解决方案

Update: it is now possible to reliably determine a tab's opener tab within a Chrome extension natively using the newly added webNavigation API, and specifically by hooking the onCreatedNavigationTarget event.

https://code.google.com/chrome/extensions/trunk/webNavigation.html

这篇关于是否可以确定Google Chrome扩展程序中的选项卡的开启者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆