3

Suppose I have a site with this code:

<!DOCTYPE html>
<body>
    <a href="https://www.google.com/">1</a><br>
    <a href="https://www.google.com/" target="_blank">2</a><br>
    <a href="https://www.google.com/" onclick="window.open(this.href);return false;">3</a><br>
</body>
</html>

but I do not want to open any new tabs or windows. I know I can drag the link into the address bar to force open the link in the current tab instead of a new one, but it is too cumbersome.

Is there a more convenient way to do it, like keyboard shortcut or maybe an extension?

3 Answers 3

2

Install LinkThing by Canibos. This Safari extension lets you configure how the browser handle the links. You can then choose to open all the onsite and offsite links in current tabs.

2

As far as I know, there's no way to force a link to open in the current tab when it has target="_blank". There's controversy over this attribute in the web development world because it's considered overbearing to force a user to open a link in a new tab when they don't want to.

Essentially, the browser is seen as the user's property, and they have the right to decide where they want links to open. This link property has been abused many times for popup ads and, while it can be useful, it generally creates a bad user experience.

I assume the only way around it would be to create (or find?) an extension that goes through all of the links on a page and removes the target attribute. It appears that @sayzlim has found one for you (see here).

As for your third example, there's no way around that other than to disable JavaScript in your browser.

2
  • The third example can be overridden, if LinkThing developer add something like this to his code: f=function(url) {document.location.href=url;};window.open=f;
    – Sergei
    Commented Jun 15, 2014 at 16:09
  • 1
    @Sergei True, but you can override it directly: window.open = function(url){ window.location.href = url;};
    – AstroCB
    Commented Jun 15, 2014 at 16:13
1

Drag & drop the link into the address bar :^) Wacky, but that's what I do.

The problem with many fancy tab extensions is that they try to have you set a complicated policy and set of rules for modelling how tabs should behave. Instead you usually want some simple sensible defaults, and more agency and control: you want some clue what clicking a link will end up doing, and you want to be able to override that when desired.

Safari did a great thing even early on, it didn't just show the url of the hovered link at the bottom of the window, it told you whether it will open it in the same or a new window, or download it, depending on the modifier keys you were pressing at the time.. So much more of that agency & control than other browsers at the time.

Even today though, its still missing being able to override the link's attributes for opening in another window/tab and force using the same one. Also there's no control in whether a new tab opens to the immediate right of the current one or at the far right.

I'd like to see a browser extension that adds those features. Firefox had a "Open in current tab" extension a while ago but it broke, although choosing "Open" from Firefox's context menu on a link seems to do it at least sometimes, although kinda voodoo since it just says "Open" and you don't know what's going to happen for sure.

UPDATE: I originally lumped LinkThing in among the extensions that have rules but little immediate control, however newer versions of this seem to have lots more control than I remember. Installing it

You must log in to answer this question.

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