Jump to content

Force all external links into a new tab?

Go to solution Solved by Guest,

Recommended Posts

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
  • 1 month later...
  • Solution

Usually I just make the link say:


<a href="http://www.whatever.com" target="_blank">link text</a>

So, pretty much just adding target="_blank" inside your link code will make clicking the link open a new tab (or window; depending on the visitor’s browser preferences).

Not sure how to code it to be universal, or if you can. I’ve only ever done it on individual link codes.

Edited by llmodbls
Format
Link to comment
  • 3 months later...
  • 1 month later...
  • 7 months later...
  • 1 month later...
  • 1 month later...
  • 1 month later...
  • 4 months later...
  • 10 months later...

I made and account on this site JUST to answer this. That's how much thankful I am.I've been struggling with this for like 2 hours, damn it! Your answer just solved it automagically.

I have a page with dynamic content generated through a php function and trying to assign the target blank attribute to links within a div class didn't work. Your solution just did.

THANK YOU!!!!!!!!!!!!!!!!!!!!!!!

Link to comment
  • 2 years later...
  • 4 months later...

Hi all, I tried adding target="_blank" to the end of my redirect url but it isn't working. I've waited approximately 30mins and it still isn't working. Any suggestions?

This is what it currently looks like: https://embodhii.org/emotional-freedom2pxiu8yh"target="_blank

Thanks in advance!

Link to comment

@clro it should be

<a href="https://embodhii.org/emotional-freedom2pxiu8yh" target="_blank">Text link</a>

or

<a href="https://embodhii.org/emotional-freedom2pxiu8yh" target="_blank">https://embodhii.org/emotional-freedom2pxiu8yh</a>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
  • 6 months later...

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>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Link to comment
  • 2 months later...

I came across this similar issue when displaying blog posts in a summary block. If the "Link Post Title to Source URL" option is selected, there is no way to make the link open in a new tab.

I found a solution in another post on this form that is counter intuitive but seems to work. Adding "target="_blank to the end of the Source URL will add the target="_blank" to the html. For example: https://link-to-outside-source.com"target="_blank  Yes, I know, the code looks wrong if you are use to writing html, but try it. Plus, no JS is required for those on the lower level subscriptions. 

Link to comment
  • 1 month later...

This is really easy to do, but Squarespace makes you go through several steps.

All you need to do is go to the page with the link you want to edit. Choose Edit Page and then highlight the link. This should bring up the link editor (if not you can click the link button on the toolbar.)

Now this is where it gets tricky. You have to go to edit, THEN you have to click the gear icon, THEN you need to switch the toggle switch to open link in new window. THEN you have to click save at the top of the link editor window. THEN you have to click "apply' at the bottom of the little link editor box. THEN you have to click on "save" at the top of the page editor to save your page.

Edited by aladdinsane
word
Link to comment
  • 2 weeks later...

It worked!

On 7/15/2020 at 7:13 AM, Tarjo said:

I came across this similar issue when displaying blog posts in a summary block. If the "Link Post Title to Source URL" option is selected, there is no way to make the link open in a new tab.

I found a solution in another post on this form that is counter intuitive but seems to work. Adding "target="_blank to the end of the Source URL will add the target="_blank" to the html. For example: https://link-to-outside-source.com"target="_blank  Yes, I know, the code looks wrong if you are use to writing html, but try it. Plus, no JS is required for those on the lower level subscriptions. 

You are the only person in this whole thread who actually responded adequately to the problem of using the "Clickthrough URL" field in gallery image settings, and your solution totally works, as weird as it is! Thanks so much for solving a problem I've had for a long time! Helpful to know it works for the "Link Post Title to Source URL" feature too.

Link to comment
  • 2 months later...

Hi I wonder if anyone can help. 

I'm also trying to set up a site so that all external links open in a new tab, but without affecting the site navigation. 

I've tried the following:

1.  putting this in the header

<base target="_blank"/>

Which worked perfectly, except that now all navigation opened in a new tab. 

 

2. applying this to a block and putting it in the header (in advanced > code injection)

<base #yourBlockId target="_blank"/>

for example <base #block-yui_3_17_2_1_1605228030617_24171 target="_blank"/>

but it didn't do anything

 

3. I have put "target="_blank to the end of all the Source URLs in blog posts. 

Initially I thought this was working, but it seems to be erratic - one will open in a new tab, another won't. 

 

Does anyone have any idea what I'm doing wrong? You can see the site at shopportunity.ie

Any advice would be hugely appreciated!

Link to comment
1 hour ago, kathryn said:

Hi I wonder if anyone can help. 

I'm also trying to set up a site so that all external links open in a new tab, but without affecting the site navigation. 

I've tried the following:

1.  putting this in the header


<base target="_blank"/>

Which worked perfectly, except that now all navigation opened in a new tab. 

 

2. applying this to a block and putting it in the header (in advanced > code injection)


<base #yourBlockId target="_blank"/>

for example <base #block-yui_3_17_2_1_1605228030617_24171 target="_blank"/>

but it didn't do anything

 

3. I have put "target="_blank to the end of all the Source URLs in blog posts. 

Initially I thought this was working, but it seems to be erratic - one will open in a new tab, another won't. 

 

Does anyone have any idea what I'm doing wrong? You can see the site at shopportunity.ie

Any advice would be hugely appreciated!

I also tried targeting the blocks by putting the code into the header on an individual page. 

 

<base #block-f9df908530b3c6b670da target="_blank"/>

<base #block-925ca918fe42cd9c4071 target="_blank"/>

 

into the header of https://shopportunity.ie/irishonlineaccessoriesstores

 

but it seems to also work erratically - sometimes affecting the navigation, sometimes not and only working intermittently.  I'm totally confused!!

Link to comment
On 11/27/2020 at 10:58 PM, kathryn said:

I also tried targeting the blocks by putting the code into the header on an individual page. 

 

<base #block-f9df908530b3c6b670da target="_blank"/>

<base #block-925ca918fe42cd9c4071 target="_blank"/>

 

into the header of https://shopportunity.ie/irishonlineaccessoriesstores

 

but it seems to also work erratically - sometimes affecting the navigation, sometimes not and only working intermittently.  I'm totally confused!!

Can you share link to page? We can use some JS code to achieve this.

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

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

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.