Preventing Sites From Opening New Tabs/Windows

UPDATE: There’s now a Chrome extension called TheOne which does this, so you don’t need to create your own user script.

 

I wrote earlier about why it’s wrong for websites to force links to open in a new tab or window,  but it’ll probably be at least a few years before the majority of clients and web developers finally come around. In the mean time it’d be nice for users to have a way to prevent their browsers from implementing the practice, but surprisingly there aren’t any Chrome extensions. You can create and install a user script, though.

Here’s my modified version of the script:

// ==UserScript==
// @name Open Links in Same Tab/Window
// @description Prevents websites from forcing links to open in new tabs or windows.
// @version 0.1
// ==/UserScript==

var a = document.getElementsByTagName(“a”);
for( i=0; i < a.length; i++ ) if( a[i].target == "_blank" ) a[i].target = "_self"; [/sourcecode]

2 thoughts on “Preventing Sites From Opening New Tabs/Windows

  1. This is brilliant and I’m blogging about it in my series on web browsers. Unfortunately, Greasemonkey reports that it is lacking @grant privileges and won’t run. Could you please update the script. It is invaluable. Thanks.

  2. WordPress School: Bookmarklets and User Scripts « Lorelle on WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *