Open external links in new tab/window

Get help with installation and running phpBB 3.1.x here. Please do not post bug reports, feature requests, or extension related questions here.
Suggested Hosts
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: phpBB 3.1.x is at its End of Life stage and support will NOT be provided after July 1st, 2018.
User avatar
david63
Registered User
Posts: 20646
Joined: Thu Dec 19, 2002 8:08 am

Re: Open external links in new tab/window

Post by david63 »

richey wrote: Mon Mar 13, 2017 12:20 pm I just realized that phpBB 3.2 doesn't open external links in a new tab anymore!
phpBB has not opened in a new tab since phpBB 3.0
David
Remember: You only know what you know and - you don't know what you don't know!

I now no longer support any of my extensions but they will start to become available here
User avatar
KevC
Support Team Member
Support Team Member
Posts: 72375
Joined: Fri Jun 04, 2004 10:44 am
Location: Oxford, UK
Contact:

Re: Open external links in new tab/window

Post by KevC »

richey wrote: Mon Mar 13, 2017 12:20 pm The information in this link : https://www.phpbb.com/support/docs/en/3 ... w-windows/ is outdated (
Of course it is. That's written for 3.0, in 2008.

There is a 3.2 version of ELONW which seems to work ok. Make sure you have disabled and removed any data from the 3.1 version before uploading the 3.2 one.
-:|:- Support Request Template -:|:-
Image
"Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb"
User avatar
paulie
Registered User
Posts: 116
Joined: Thu Mar 30, 2017 3:41 pm
Location: Hull, East Yorkshire.

Re: Open external links in new tab/window

Post by paulie »

For anyone not wanting to install an extension but still wanting to open external links in new windows, I stumbled across an old 'hack' that I used years ago (2008) on my board. I tried it on 3.2 and guess what? It still works a treat! Any external links posted after you have edited the files open fine, those posted before, don't.

Here's what you do:

Open: bbcode.html

Find:

Code: Select all

<!-- BEGIN url --><a href="{URL}" class="postlink">{DESCRIPTION}</a><!-- END url -->
Replace with:

Code: Select all

<!-- BEGIN url --><a href="{URL}" onclick="window.open(this.href);return false;" class="postlink">{DESCRIPTION}</a><!-- END url -->
Open: includes/functions.php

Find:

Code: Select all

case 'bbcode_htm':
return array(
'#<!\-\- e \-\-><a href="mailto:(.*?)">.*?</a><!\-\- e \-\->#',
'#<!\-\- l \-\-><a (?:class="[\w-]+" )?href="(.*?)(?:(&|\?)sid=[0-9a-f]{32})?">.*?</a><!\-\- l \-\->#',
'#<!\-\- ([mw]) \-\-><a (?:class="[\w-]+" )?href="(.*?)">.*?</a><!\-\- \1 \-\->#',
'#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/.*? \/><!\-\- s\1 \-\->#',
'#<!\-\- .*? \-\->#s',
'#<.*?>#s',
);
Replace with:

Code: Select all

case 'bbcode_htm':
return array(
'#<!\-\- e \-\-><a href="mailto:(.*?)">.*?</a><!\-\- e \-\->#',
'#<!\-\- l \-\-><a (?:class="[\w-]+" )?href="(.*?)(?:(&|\?)sid=[0-9a-f]{32})?" onclick="window\.open\(this\.href\);return false;">.*?</a><!\-\- l \-\->#',
'#<!\-\- ([mw]) \-\-><a (?:class="[\w-]+" )?href="(.*?)" onclick="window\.open\(this\.href\);return false;">.*?</a><!\-\- \1 \-\->#',
'#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/.*? \/><!\-\- s\1 \-\->#',
'#<!\-\- .*? \-\->#s',
'#<.*?>#s',
);
Upload the edited files, purge the cache, you're done!
'Life in the Air Age isn't all the brochures say ...'
User avatar
KevC
Support Team Member
Support Team Member
Posts: 72375
Joined: Fri Jun 04, 2004 10:44 am
Location: Oxford, UK
Contact:

Re: Open external links in new tab/window

Post by KevC »

I can't think of any reason why that would be better than using the extension that just requires upload and activation.
-:|:- Support Request Template -:|:-
Image
"Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb"
User avatar
paulie
Registered User
Posts: 116
Joined: Thu Mar 30, 2017 3:41 pm
Location: Hull, East Yorkshire.

Re: Open external links in new tab/window

Post by paulie »

KevC wrote: Sat Apr 08, 2017 6:42 pm I can't think of any reason why that would be better than using the extension that just requires upload and activation.
Because when I used the extension, sometimes it worked, sometimes it didn't. This works for me every single time therefore it's better. As the saying goes, the old ones are the best!
'Life in the Air Age isn't all the brochures say ...'
User avatar
RMcGirr83
Former Team Member
Posts: 22016
Joined: Wed Jun 22, 2005 4:33 pm
Location: Your display
Name: Rich McGirr

Re: Open external links in new tab/window

Post by RMcGirr83 »

The extension you are referring to works perfectly well. It's odd that you didn't post in the support area for the extension of it didn't work all the time for you.
Former Modifications/Extensions Team Member | My extensions | github | All requests for support via PM will be ignored
Appreciate the extensions/mods/support then buy me a beer Image
User avatar
paulie
Registered User
Posts: 116
Joined: Thu Mar 30, 2017 3:41 pm
Location: Hull, East Yorkshire.

Re: Open external links in new tab/window

Post by paulie »

RMcGirr83 wrote: Sat Apr 08, 2017 6:57 pm The extension you are referring to works perfectly well. It's odd that you didn't post in the support area for the extension of it didn't work all the time for you.
If it did work perfectly well, I would've kept it. I'm not having a go, don't take it personally, it's a very good extension but it just didn't work for me, simple as that.

If it's of any use to you as the writer, after I installed your extension, I tested it on loads of different links to all manor of different websites all over the world and all opened in an external window. However, one of those that wouldn't for reasons I don't understand, was the Beebs website. No matter what I tried - editing the post, different combinations, it still wouldn't open in a new window. Very odd.

Rather than post in the support area, I tried the old hack first and that worked instantly so I had no need to seek support for the extension as I had deleted it.
'Life in the Air Age isn't all the brochures say ...'
sakm
Registered User
Posts: 713
Joined: Sun Jan 21, 2007 8:14 pm
Location: Hull, uk
Name: Stu
Contact:

Re: Open external links in new tab/window

Post by sakm »

I run the extension on my forum with no problems
User avatar
Mick
Support Team Member
Support Team Member
Posts: 26546
Joined: Fri Aug 29, 2008 9:49 am

Re: Open external links in new tab/window

Post by Mick »

paulie wrote: Sat Apr 08, 2017 7:04 pmIf it's of any use to you as the writer
Please post your findings in the dedicated support area for your extension.

Note that this support topic was marked as Image (solved) a while ago. If you have further issues on this subject please start your own (support/extension) topic.
  • "The more connected we get the more alone we become" - Kyle Broflovski©
  • "The good news is hell is just the product of a morbid human imagination.
    The bad news is, whatever humans can imagine, they can usually create.
    " - Harmony Cobel
user751139
Registered User
Posts: 89
Joined: Thu Oct 01, 2009 2:46 am

Re: Open external links in new tab/window

Post by user751139 »

paulie wrote: Sat Apr 08, 2017 6:39 pm For anyone not wanting to install an extension but still wanting to open external links in new windows, I stumbled across an old 'hack' that I used years ago (2008) on my board. I tried it on 3.2 and guess what? It still works a treat! Any external links posted after you have edited the files open fine, those posted before, don't.

Here's what you do:

Open: bbcode.html

Find:

Code: Select all

<!-- BEGIN url --><a href="{URL}" class="postlink">{DESCRIPTION}</a><!-- END url -->
Replace with:

Code: Select all

<!-- BEGIN url --><a href="{URL}" onclick="window.open(this.href);return false;" class="postlink">{DESCRIPTION}</a><!-- END url -->
Open: includes/functions.php

Find:

Code: Select all

case 'bbcode_htm':
return array(
'#<!\-\- e \-\-><a href="mailto:(.*?)">.*?</a><!\-\- e \-\->#',
'#<!\-\- l \-\-><a (?:class="[\w-]+" )?href="(.*?)(?:(&|\?)sid=[0-9a-f]{32})?">.*?</a><!\-\- l \-\->#',
'#<!\-\- ([mw]) \-\-><a (?:class="[\w-]+" )?href="(.*?)">.*?</a><!\-\- \1 \-\->#',
'#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/.*? \/><!\-\- s\1 \-\->#',
'#<!\-\- .*? \-\->#s',
'#<.*?>#s',
);
Replace with:

Code: Select all

case 'bbcode_htm':
return array(
'#<!\-\- e \-\-><a href="mailto:(.*?)">.*?</a><!\-\- e \-\->#',
'#<!\-\- l \-\-><a (?:class="[\w-]+" )?href="(.*?)(?:(&|\?)sid=[0-9a-f]{32})?" onclick="window\.open\(this\.href\);return false;">.*?</a><!\-\- l \-\->#',
'#<!\-\- ([mw]) \-\-><a (?:class="[\w-]+" )?href="(.*?)" onclick="window\.open\(this\.href\);return false;">.*?</a><!\-\- \1 \-\->#',
'#<!\-\- s(.*?) \-\-><img src="\{SMILIES_PATH\}\/.*? \/><!\-\- s\1 \-\->#',
'#<!\-\- .*? \-\->#s',
'#<.*?>#s',
);
Upload the edited files, purge the cache, you're done!
Thank you Sir/Madam - it worked perfectly on 3.2.1 - You are a star :)
Locked

Return to “[3.1.x] Support Forum”