Jump to content

Open specific links in same tab and others in new tab

Recommended Posts

Hi, I added these two custom css scripts to my website. One is for making the images in the carousel slider clickable. The other is for making all external links 'nofollow'. They both have target="_blank" and so the built in toggle switch in squarespace is not changing it. 

But I need to make some links open in a new tab and some (especially the internal ones) open in the same tab.

Will appreciate your advice on this.

website
Password: 4204200

The first carousel section with several slides should open in new tab when the toggle switch "open in new tab" is disabled. The other external links set to "open in new tab" should continue doing this.

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
  $( ( ) => {
  
    const selector = '.user-items-list-carousel__slides .list-item';
    
    $( selector ).each ( function ( ) {
    
      const $this = $( this );
      
      $( $this ).click ( function ( ) {
      
      const url = $( '.list-item-content__button', $this )
      
        .attr ( 'href' );
        
      $( `<a href="${ url }" target="_blank">` )
      
      	.get ( 0 )
        
        .click ( );
        
      } );
      
    } );
    
  } );
</script>
<script>

 

<script>
  (function () {
    window.addEventListener('load', function () {
      var fixAmazonLinks = function () {
        var amazonLinks = document.querySelectorAll(
          'a[href*="https://"], a[href*="www."]'
        );

        if (!amazonLinks instanceof NodeList) {
          return;
        }

        amazonLinks.forEach(link => {
          link.rel = 'nofollow';
          link.target = '_blank';
        });
      };
      fixAmazonLinks();
    });
  })();
</script>

 

Link to comment
  • Replies 0
  • Views 1.1k
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

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


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.