Stop Sites From Opening New Tabs Chrome

Posted on

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.

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!!

Oneezy
OneezyOneezy
2,2875 gold badges30 silver badges56 bronze badges

1 Answer

Stop

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 target attributes off the anchor elementsand set all target attributes of anchor elements to _self.

Caveats:

  1. There are dynamically inserted elements (including anchor elements) on many pages.
  2. There are dynamically changing elements (including anchor elements) on some pages.
  3. 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:

Stop Sites From Opening New Tabs Chrome

content.js:

gkalpak

How To Stop Websites From Opening New Tabs Chrome Android

gkalpak

Chrome Is Opening New Tabs

42.9k7 gold badges87 silver badges106 bronze badges
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.

Not the answer you're looking for? Browse other questions tagged google-chromegoogle-chrome-extensionwindowsettingsbrowser-support or ask your own question.