Chrome扩展程序是否可以更改Chrome设置(在新窗口/弹出窗口中打开)? [英] Can a Chrome extension change Chrome settings (open in new window / popup)?
问题描述
类似的问题被问到这里,但没有令人满意的答案。< b
我试图用扩展名更改2个Chrome设置。
- 导致浏览器打开新链接为
- 导致浏览器接受来自特定网址的弹出窗口
我已经查看了文档,但找不到答案。
任何人都可以帮助我解决这个问题吗? 解决方案
没有设置将链接作为选项卡而不是窗口打开。您可以通过 chrome.contentSettings
更改弹出窗口首选项> API。
所有请求的功能也可以间接启用。一些想法:
- 新窗口,而不是选项卡。
- 检测创建通过
chrome.tabs.onCreated
。
- 检测窗口是否在另一个窗口内打开:
使用tab.id
属性从上一个事件侦听器获取窗口
对象,使用chrome.extension.getViews
。然后,检查window.opener
属性以确定链接是否从另一个选项卡打开。
这个链接可能不起作用rel =noreferrer
属性集。
使用chrome.windows.create
,将tabId
。该选项卡将从其上一个窗口中分离出来,并附加到新窗口中。
- 检测创建通过
- 您可以重写
window.open
方法,它调用chrome.tabs.create
和chrome.windows.create
创建一个新的弹出窗口。
全局重写可以通过使用 status ==扩展/ tabs.html#event-onCreated =nofollow>chrome.tabs.onUpdated
。完成,然后使用chrome.extension.getViews
来更改window.open
方法。确保您创建了缓存版本的窗口
onject,以便在必要时仍可使用原始方法。
这些是必要的信息+文档链接,可帮助您创建所需的功能。祝你好运;)
A similar question was asked here but without a satisfying answer.
I'm trying to do change 2 chrome settings with the extension.
- Cause the browser to open new links as tabs and not windows.
- Cause the browser to accept pop ups from a specific URL
I have looked in the documentation, but cannot find the answer.
Could anyone help me with this one?
There's no setting to open links as tabs instead of windows. You can change the popup preference through the chrome.contentSettings
API.
All of the requested features can also be enabled indirectly. Some ideas:
- New window instead of tabs.
- Detect creation of tabs through
chrome.tabs.onCreated
. - Detect whether the window was opened from inside another window:
Use thetab.id
property from the previous event listener to get thewindow
object, usingchrome.extension.getViews
. Then, check thewindow.opener
property to determine whether the link was opened from another tab.
This might not work when the link has therel="noreferrer"
attribute set.
Create a new window usingchrome.windows.create
, passing thetabId
. The tab will be detached from its previous window, and attached to the new window.
- Detect creation of tabs through
- You can rewrite the
window.open
method, which invokeschrome.tabs.create
andchrome.windows.create
to create a new popup window.
A global rewrite can be done by detecting page loads usingchrome.tabs.onUpdated
, withstatus=="complete"
, then usechrome.extension.getViews
to change thewindow.open
method. Make sure that you create a cached version of thewindow
onject, so that the original method is still available when necessary.
These are the necessary information + documentation links which help you to create the desired functionaily. Good luck ;)
这篇关于Chrome扩展程序是否可以更改Chrome设置(在新窗口/弹出窗口中打开)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!