open forum post links in a new tab

feedback, comments and suggestions pertaining to the stardot forum
Post Reply
User avatar
lovebug
Posts: 425
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

open forum post links in a new tab

Post by lovebug »

by adding an onclick and window.open to bbcode.html and functions.php it will allow forum post links to open in a new tab instead of the current tab so preserving the forum

open bbcode.html and 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 and 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',
);
Image
User avatar
danielj
Posts: 8752
Joined: Thu Oct 02, 2008 5:51 pm
Location: Manchester
Contact:

Re: open forum post links in a new tab

Post by danielj »

We don't mess with the base code - it always ends up causing issues when updating. And undoubtedly there would be a number of users who wouldn't like the functionality. Right click and "open link in new tab" does the job if that's your thing :)
d.
guesser
Posts: 599
Joined: Mon Jun 26, 2006 10:21 pm
Contact:

Re: open forum post links in a new tab

Post by guesser »

I find forcing links to open in a new tab to be unnecessary and obnoxious in many cases.
Browsers already give the user the choice of whether to open links in new tabs if they want to.
Various teletext things including a web based teletext editor which can export as mode 7 screens.
Join the Teletext Discord for teletext chat.
User avatar
baz4096
Posts: 124
Joined: Sat Apr 10, 2021 3:51 pm
Location: Baildon, West Yorkshire
Contact:

Re: open forum post links in a new tab

Post by baz4096 »

guesser wrote:
Tue Jul 13, 2021 2:50 pm
I find forcing links to open in a new tab to be unnecessary and obnoxious in many cases.
Browsers already give the user the choice of whether to open links in new tabs if they want to.
I totally agree. If it were a case of the default links preventing new tabs or windows from being used, I can see the need for change. However as it stands, middle click, CMD-Click or CTRL-Click, right click - Open in New Tab/Window already offer the best flexibility.
User avatar
baz4096
Posts: 124
Joined: Sat Apr 10, 2021 3:51 pm
Location: Baildon, West Yorkshire
Contact:

Re: open forum post links in a new tab

Post by baz4096 »

Of course, there's nothing to stop individual users installing a script modification plugin for their browser that will do what lovebug is wanting, like Greasemonkey, Tampermonkey etc.
User avatar
lovebug
Posts: 425
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

Re: open forum post links in a new tab

Post by lovebug »

all good points, thanks

i'll write a greasemonkey script :lol:
Image
User avatar
lovebug
Posts: 425
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

Re: open forum post links in a new tab

Post by lovebug »

Code: Select all

// ==UserScript==
// @name           New Tab in phpBB3
// @namespace      https://stardot.org.uk/
// @description    Makes links in posts in phpBB3 boards open new tabs.
// ==/UserScript==

var newWin = function(ev) {
    var win = window.open(ev.target.href);
    if (win) ev.preventDefault();
};

var links = document.evaluate(
        "//div[@class='content']//a[not(@onclick) and not(@href='#')]",
        document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

for (var i = 0; i < links.snapshotLength; i++) {
    var link = links.snapshotItem(i);
    link.addEventListener("click", newWin, true);
}
Image
User avatar
lovebug
Posts: 425
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

Re: open forum post links in a new tab

Post by lovebug »

omg this script breaks the image links
i'll look into it
Image
User avatar
lovebug
Posts: 425
Joined: Sun Jan 31, 2021 5:07 pm
Location: Magrathea
Contact:

Re: open forum post links in a new tab

Post by lovebug »

testing...https://lovebug.ml
meh
Image
Post Reply

Return to “stardot FORUM”