Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0

Force all external links into a new tab?


joeljanski

Question

I am trying to get the clickthrough URL of each image in my galleries to open in a new tab. I did some digging and I noticed that each gallery image has the <div class="margin-wrapper"> on it. So I am thinking if I can have anything that has that class open in a new tab I should be good?

How can I change all external links contained within <div class="margin-wrapper"> to automatically open in a new blank target tab?

Edited by acalvo
retag
Link to comment

Recommended Posts

  • 0
On 5/13/2020 at 1:04 AM, tuanphan said:

try adding to Code Injection Footer

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('[href*="mail"]').attr('target','_blank');
});
</script>

 

I put this in the Code Injection Footer, but it doesn't seem to work (I'd like all external links to open in a new window). Any suggestions?

Thank you tuanphan!!

Link to comment
  • 0
On 10/11/2021 at 5:35 AM, Naomi_ said:

I put this in the Code Injection Footer, but it doesn't seem to work (I'd like all external links to open in a new window). Any suggestions?

Thank you tuanphan!!

above code for email only, try this new code

<script>
  var all_links = document.querySelectorAll('a');
for (var i = 0; i < all_links.length; i++){
       var a = all_links[i];
       if(a.hostname != location.hostname) {
               a.rel = 'noopener';
               a.target = '_blank';
       }
}
</script>

 

Email me if you have need any help (free, of course.). Answer within 24 hours.

How to: Setup password & share url - Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...