问题
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?
回答1:
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, using chrome.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 the rel="noreferrer" attribute set.
Create a new window using chrome.windows.create, passing thetabId
. The tab will be detached from its previous window, and attached to the new window.
- You can rewrite the window.open method, which invokes chrome.tabs.create and chrome.windows.create to create a new popup window.
A global rewrite can be done by detecting page loads using chrome.tabs.onUpdated, withstatus=="complete"
, then use chrome.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 ;)
来源:https://stackoverflow.com/questions/9871327/can-a-chrome-extension-change-chrome-settings-open-in-new-window-popup