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.

  • Noo, don’t do that ! These curly quotes in my question are totally wrong ! This sort of “correction” smells of Microsoft Word. I have written correctly target="_blank". – Nicolas Barbulesco Dec 7 '13 at 19:52
  • I have tried `the backtick trick` — to no avail. – Nicolas Barbulesco Dec 7 '13 at 19:57
  • Now I have edited the title, to circumvent the auto-“correction”. The site wrongly transforms target="_blank" into target=“_blank”, à la Microsoft. Incredible, but true. – Nicolas Barbulesco Dec 7 '13 at 20:51

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.

  • I have adopted the extension LinkThing ! A nice one, despite the weird way to go in its prefs. However, it does not work with JavaScript off, and it fails to work on some link(s). – Nicolas Barbulesco Jan 4 '14 at 17:48

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')


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

  • What do you call a “userscript” ? Thank you, but this looks complicated. – Nicolas Barbulesco Dec 7 '13 at 20:17
  • 1
    It's basically a JavaScript script that runs on pages specified in the @include line (* = all pages). You can install it using one of many 'Greasemonkey' extensions, and I recommend NinjaKit. Simply download and install the Safari extension, then click the install link in my answer. The script I've written above will get all a links on the page, and if their attribute is _blank it will change it to _self. – grg Dec 7 '13 at 20:23
  • Thank you, but I don't want that. – Nicolas Barbulesco Dec 7 '13 at 20:44
  • @Nicolas Why not? – grg Dec 7 '13 at 20:45
  • 1
    @Nicolas If it's only certain domains that you want the script to run on (like I did for my remote intranet), you can limit the script to only run on that domain by changing the @include line or lines to one or more domains. – grg Dec 7 '13 at 21:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .