Jump to content

How to get links to open a new tab ONLY on one page

Recommended Posts

  • Replies 11
  • Views 1.4k
  • Created
  • Last Reply

When you are testing the base tag are you in edit mode? If so then the edit mode overrides the base tag behaviour in my testing.

Keep your base tag in the Page Header Code Injection for the page you want the links to open to a new page.

Then the trick is to get out of edit mode to test the behavior is correct.

Hit the arrow or the escape key (if you have that enabled).

1203937310_ScreenShot2020-09-26at11_06_39PM.png.ba73383c3653873cbeb6b7baa915c30f.png

Once out of edit mode you should see the following URL.

560640756_ScreenShot2020-09-26at11_08_05PM.png.4159cc6cb3a684377817f8a263f66128.png

To that URL add ?noredirect and hit return to go to that URL.

358966355_ScreenShot2020-09-26at11_10_26PM.png.a7b1f55af5a3995556121ea0ae1289a5.png

This should help you not fallback into edit mode by accident.

Now click on a link on that page. Does it open a new window or tab?

To get back into edit mode hit escape key (if enabled). Or add "config/" (without the quotes) to the base URL of your website.

Let us know how it goes.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

It's not an issue of whether or not the code is allowing for the tabs to open up in a new tab. It's that with the code, every single link throughout the whole domain opens up into a new tab when we've tested it outside of edit mode. We'd like to know how we can get it only for the particular story page, rather than throughout the whole website. Any idea might be up with it?

Link to comment

I am unable to reproduce the behaviour you describe. I put that base tag in Page Settings > Advanced > Page Header Code Injection for a test page on my test site. Only that page opens links into a new window/tab. Links on other pages are unaffected.

459629545_ScreenShot2020-09-30at11_43_42PM.png.61f8513e3c7ee040e283e371e0b2cb42.png

1622863039_ScreenShot2020-09-30at11_44_21PM.png.e1f7d5b3310c57287431ff34dcabc0e2.png

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

Hmm. After a bit of experimenting, it seems that the code makes all of the links in the site header open up in a new tab. I would like to be able for it to only happen for the "Read more" links I have under the blog stories. With that code, and a site header, you should see the behavior replicate itself in the site header.

Link to comment
  • 2 weeks later...

Add the following to Settings > Advanced > Code Injection > HEADER.

<script src="//ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

Add the following to Page Settings > Advanced > PAGE HEADER CODE INJECTION for the page.

<script>

  $( ( ) => {
  
    $( '.blog-more-link' ).attr ( 'target', '_blank' );
    
    } );
    
  </script>

Let us know how it goes.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

When I click on read more links on that page a new tab is opened in my browser. I can see that the code you added is working.

The following pics show the code is there and working.

599176596_ScreenShot2020-10-15at12_28_08PM.png.22287e484f5b8c95c4e8cc25ad8a390e.png

 

1252510638_ScreenShot2020-10-15at12_27_23PM.png.599242ec446d88a03fb60ba8506c2efb.png

My thinking is that your browser is blocking the target _blank behaviour. Perhaps a security setting to prevent pop ups. It could also be ad blocker software.

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.