This section contains detailed articles elaborating on some of the common issues phpBB users encounter while using the product. Articles submitted by members of the community are checked for accuracy by the relevant phpBB Team. If you do not find the answer to your question here, we recommend looking through the Support Section as well as using the Site Wide Search.

Links Opening New Windows

Description: Describes how to make links on phpBB3 boards open new windows.

In Categories:

Link to this article: Select All
[url=https://www.phpbb.com/support/docs/en/3.0/kb/article/links-opening-new-windows/]Knowledge Base - Links Opening New Windows[/url]

Compared to phpBB3, links in phpBB2 had a slightly different behaviour: When you clicked them, they opened a new window with the requested page. This was changed in phpBB3 for a couple of reasons, but one of the most important ones was the goal to achieve XHTML 1.0 Strict-validation for the whole board.


If you still want to get the same behaviour on your new phpBB3 board, there are a couple of small modifications have you to make, which this guide should hopefully explain in enough detail.

Modifying auto-detected links

First of all, make auto-detected links (those that you didn't wrap with the url-BBCode) open new windows when getting clicked. Therefor open the includes/functions_content.php and look for following line (which should be around line 592):

Code: Select all

    $html    = "$whitespace<!-- $tag --><a$class href="$url">$text</a><!-- $tag -->$append";
            


And replace it with following line:

Code: Select all

    if ($type == MAGIC_URL_EMAIL)
    {
        $html    = "$whitespace<!-- $tag --><a$class href="$url">$text</a><!-- $tag -->$append";    
    
}
    else 
    
{
        $html    = "$whitespace<!-- $tag --><a$class href="$url" onclick="window.open(this.href);return false;">$text</a><!-- $tag -->$append";
    } 


BBCode URLs

Next open the bbcode.html of your style (if you're using prosilver, this would be the styles/prosilver/template/bbcode.html file) and look for following line:

Code: Select all

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


Now replace it with this line:

Code: Select all

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


Help phpBB read the output again

Last but not least, you should also do the following change which will allow the created HTML output to be parsed again by phpBB: Open the includes/functions.php and replace this segment which you should find around line 2740...

Code: Select all

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


... with this one:

Code: Select all

      case 'bbcode_htm':
         return array(
            '#<!\-\- e \-\-><a href="mailto:(.*?)">.*?</a><!\-\- e \-\->#',
            '#<!\-\- l \-\-><a (?:class="[\w-]+" )?href="(.*?)(?:(&amp;|\?)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',
         );


And since you've updated also a template file, don't forget to also purge your board's cache through the respective button on the frontpage of your board's admin panel.

Note: The change will not affect existing posts, you must edit them so they can be reprocessed.