Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer

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.

share|improve this answer
    
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 Jun 15 at 16:09
1  
@Sergei True, but you can override it directly: window.open = function(url){ window.location.href = url;}; –  AstroCB Jun 15 at 16:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.