Advertisement:

Author Topic: Opening a link in one tab, following links in that tab  (Read 245 times)

Offline spiros

  • Language Moderator
  • SMF Hero
  • *
  • Posts: 1,718
  • Gender: Male
  • A different point of view
    • spiros.doikas on Facebook
    • doikas on LinkedIn
    • @greektranslator on Twitter
    • Greek Translation
Opening a link in one tab, following links in that tab
« on: March 09, 2019, 03:00:29 PM »
EDIT: got it, it was the noopener noreferrer bit that stopped it.

This is in search.template.php [Tab 1]

I want the first link to open in new tab [Tab 2] and any consecutive links that are clicked on [Tab 1] to open in [Tab 2].


Code: [Select]
<li>
<a class="button_strip_print" href="https://www.google.com/search?q=', !empty($context['search_params']['search']) ? $context['search_params']['search'] : '', '" target="_blank" title="Google search" rel="noopener noreferrer nofollow"><span class="last">G</span></a>
</li>

I tried linking to an external js and renaming _blanks to mytarget, but did not do it.

Code: [Select]
var targetlinks = document.querySelectorAll('[target="mytarget"]');

var opentarget = function(e){
    if( "mytarget" in window ){
         mytarget.location.href = e.target.href;   
    }
    else {
         window.mytarget = window.open( e.target.href, 'mytarget' );   
    }
    e.preventDefault();
};

[].slice.call( targetlinks ).forEach( function(link){
    link.addEventListener('click', opentarget );
});

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 70,508
    • StoryBB/StoryBB on GitHub
Re: Opening a link in one tab, following links in that tab
« Reply #1 on: March 09, 2019, 03:29:02 PM »
All you had to do was name the target the same each time; _blank opens in a new tab regardless, but a named target always opens in that target.

noopener noreferrer stops that, of course, and is also potentially a security measure you're getting rid of.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline spiros

  • Language Moderator
  • SMF Hero
  • *
  • Posts: 1,718
  • Gender: Male
  • A different point of view
    • spiros.doikas on Facebook
    • doikas on LinkedIn
    • @greektranslator on Twitter
    • Greek Translation
Re: Opening a link in one tab, following links in that tab
« Reply #2 on: March 10, 2019, 04:20:06 AM »
Yes, you are right, but I will have to make do with that, unless someone knows a different way of doing it that would preserve the security measures...