Stop Sites From Opening New Tabs Chrome
Mar 16, 2018 - When you open Chrome, you expect a new tab or a homepage to. Tray from websites and extensions even when Chrome appears closed.
- How To Stop Websites From Opening New Tabs Firefox
- How To Stop Websites From Opening New Tabs Chrome Android
- Chrome Is Opening New Tabs
Is their a way to keep all pages on the internet in a single window through Chromes browser settings? or a addon/plugin that I can do this with?
I don't want web pages to open up in new tabs and/or new windows when I click on some links.
Let me know if anyone has any suggestions!, Thanks!!
1 Answer
Possible approach:
One approach could be building an extension that injects a content script in every page. This content script would parse the DOM and remove all and set all target
attributes off the anchor elementstarget
attributes of anchor elements to _self
.
Caveats:
- There are dynamically inserted elements (including anchor elements) on many pages.
- There are dynamically changing elements (including anchor elements) on some pages.
- Not all pages/tabs are opened through links (e.g. some page could use
window.open()
).
Solution:
You could use a MutationObserver that watches for anchor elements being inserted or having their target
attribute modified and make the appropriate adjustments.
You still need to take care of tabs opened by other means (e.g. window.open()
) if it is extremely important to you (but those cases should be very very few, so it might not be worth the trouble).
How To Stop Websites From Opening New Tabs Firefox
Sample code:
manifest.json:
content.js:
gkalpak