Preventing Sites From Opening New Tabs/Windows

by Ian Dunn

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";

Leave a Comment

Add this ribbon to your WordPress website re-abolish slavery