How to have Safari open links with the evil target attribute open in the same tab?

In some pages, there are (still) links marked target="_blank".

Safari opens such link in a new tab.

How to have Safari open such link in the same tab ?

I have Safari 7 on Mavericks. I have older Safari as well.


Install the Safari extension LinkThing to customize links behavior. It should be able to solve your problem, additionally, you can also customize the onsite and offsite links behavior.


You can use a userscript such as the following:

var a = document.getElementsByTagName('a');
for (i=0;i<a.length;i++)
    if (a[i].getAttribute('target')=='_blank')
        a[i].setAttribute('target','_self');

Install

I recommend installing using NinjaKit for Safari, but other userscript extensions also work.