5

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.

3
  • 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". Dec 7, 2013 at 19:52
  • I have tried `the backtick trick` — to no avail. Dec 7, 2013 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. Dec 7, 2013 at 20:51

2 Answers 2

3

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.

1
  • 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). Jan 4, 2014 at 17:48
2

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.

5
  • What do you call a “userscript” ? Thank you, but this looks complicated. Dec 7, 2013 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, 2013 at 20:23
  • @Nicolas Why not?
    – grg
    Dec 7, 2013 at 20:45
  • For several reasons. The main reason is : I don’t want a mill running in all the links of all the pages ! :-) Dec 7, 2013 at 20:50
  • 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, 2013 at 21:05

You must log in to answer this question.

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