Quick way to set external links to open in new tab?

This forum is for all Flare issues related to the HTML5, WebHelp, WebHelp Plus, and Adobe Air Targets
Post Reply
StraygoatWriting
Sr. Propeller Head
Posts: 125
Joined: Thu Mar 05, 2015 4:24 am
Location: Chesterfield, Derbyshire, UK
Contact:

Quick way to set external links to open in new tab?

Post by StraygoatWriting »

Does anyone know of a quick way to set projects to open external links (not internal) in a new tab? I tried using a script I found online, but it isn't having any effect.
NorthEast
Master Propellus Maximus
Posts: 6363
Joined: Mon Mar 05, 2007 8:33 am

Re: Quick way to set external links to open in new tab?

Post by NorthEast »

If 'external' means any links that aren't relative, then try this jQuery:

Code: Select all

$("a[href^='http://']").attr("target","_blank");
StraygoatWriting
Sr. Propeller Head
Posts: 125
Joined: Thu Mar 05, 2015 4:24 am
Location: Chesterfield, Derbyshire, UK
Contact:

Re: Quick way to set external links to open in new tab?

Post by StraygoatWriting »

Thanks Dave, you're a star. That looks quite similar to the script I had actually, but slightly different. I'll give it a go.
Marinahg
Jr. Propeller Head
Posts: 1
Joined: Wed Jul 22, 2020 1:51 am

Re: Quick way to set external links to open in new tab?

Post by Marinahg »

Thank you both!

I've tried to use your script, but it didn't work for me until I modified the attribute as follows (I've also adapted the script to be used with https links):

<script type="text/javascript">/<![CDATA[/
$("a[href^='https://']").attr('target="_blank"');/]]>/</script>

Hope this helps :)
NorthEast
Master Propellus Maximus
Posts: 6363
Joined: Mon Mar 05, 2007 8:33 am

Re: Quick way to set external links to open in new tab?

Post by NorthEast »

Yep, my code wouldn't work with https, so matching just 'http' might be a better solution, so it covers both http/https.

Code: Select all

$("a[href^='http']").attr("target","_blank");
The attribute function works fine using either .attr("target","_blank") or .attr('target="_blank"')
Post Reply