Make links open in new window?

Do not post support requests, bug reports or feature requests. Discuss phpBB here. Non-phpBB related discussion goes in General Discussion!
Suggested Hosts

Make links open in new window?

Postby Paul UK » Wed May 23, 2007 10:25 am

Is there anyway (apart from editing the php) to make a link in a post open up in a new window when you click on it? I know you can right click on the link and select open in a new window but people don't think to do that. They are moaning at me that they close the window down and the forum has gone too, so they'd like links in new windows.
Paul UK
Registered User
 
Posts: 12
Joined: Mon May 21, 2007 11:17 am

Re: Make links open in new window?

Postby karlsemple » Wed May 23, 2007 10:31 am

Not sure this is still working as it was for beta5, but I am sure it has not changed to the point it will not work in the RC
Image
User avatar
karlsemple
Former Team Member
 
Posts: 39802
Joined: Mon Nov 01, 2004 8:54 am
Location: Hereford, UK

Re: Make links open in new window?

Postby Kevin Clark » Wed May 23, 2007 10:37 am

User avatar
Kevin Clark
Support Team Member
Support Team Member
 
Posts: 59407
Joined: Fri Jun 04, 2004 10:44 am
Location: Oxford, UK

Re: Make links open in new window?

Postby Paul UK » Wed May 23, 2007 6:54 pm

Thank you both. I now have it working.
Paul UK
Registered User
 
Posts: 12
Joined: Mon May 21, 2007 11:17 am

Re: Make links open in new window?

Postby azzurri » Mon Jun 04, 2007 4:28 pm

This works but if you edit or preview a post you always get target="_blank" after the post. Doesnt look good at all. Isn't there a better solution for this problem?
azzurri
Registered User
 
Posts: 887
Joined: Fri Jul 21, 2006 7:48 pm

Re: Make links open in new window?

Postby karlsemple » Mon Jun 04, 2007 4:30 pm

karlsemple wrote:Not sure this is still working as it was for beta5, but I am sure it has not changed to the point it will not work in the RC



read further down the topic, the change in the first post does not work.... it is http://www.ktuk.net/phpBB3/viewtopic.ph ... 32#p113032
Image
User avatar
karlsemple
Former Team Member
 
Posts: 39802
Joined: Mon Nov 01, 2004 8:54 am
Location: Hereford, UK

Re: Make links open in new window?

Postby azzurri » Mon Jun 04, 2007 5:49 pm

I tried it but it doesnt work:

Jackal wrote:So based on what the user above has discovered while playing about here is the revised and working change

open styles/subsilver/templates/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}" class="postlink" target="_blank">{DESCRIPTION}</a><!-- END url -->


Open includes/functions.php

Find:
Code: Select all
 // matches a xxxx://aaaaa.bbb.cccc. ...
      $magic_url_match[] = '#(^|[\n\t (])(' . get_preg_expression('url_inline') . ')#ie';
      $magic_url_replace[] = "'\$1<!-- m --><a href=\"\$2\">' . ((strlen('\$2') > 55) ? substr(str_replace('&amp;', '&', '\$2'), 0, 39) . ' ... ' . substr(str_replace('&amp;', '&', '\$2'), -10) : '\$2') . '</a><!-- m -->'";


Replace
Code: Select all
With: // matches a xxxx://aaaaa.bbb.cccc. ...
      $magic_url_match[] = '#(^|[\n\t (])(' . get_preg_expression('url_inline') . ')#ie';
      $magic_url_replace[] = "'\$1<!-- m --><a target=\"_blank\" href=\"\$2\">' . ((strlen('\$2') > 55) ? substr(str_replace('&amp;', '&', '\$2'), 0, 39) . ' ... ' . substr(str_replace('&amp;', '&', '\$2'), -10) : '\$2') . '</a><!-- m -->'";


Find:
Code: Select all
// matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
      $magic_url_match[] = '#(^|[\n\t (])(' . get_preg_expression('www_url_inline') . ')#ie';
      $magic_url_replace[] = "'\$1<!-- w --><a href=\"http://\$2\">' . ((strlen('\$2') > 55) ? substr(str_replace('&amp;', '&', '\$2'), 0, 39) . ' ... ' . substr(str_replace('&amp;', '&', '\$2'), -10) : '\$2') . '</a><!-- w -->'";


Replace With:
Code: Select all
// matches a "www.xxxx.yyyy[/zzzz]" kinda lazy URL thing
      $magic_url_match[] = '#(^|[\n\t (])(' . get_preg_expression('www_url_inline') . ')#ie';
      $magic_url_replace[] = "'\$1<!-- w --><a target=\"_blank\" href=\"http://\$2\">' . ((strlen('\$2') > 55) ? substr(str_replace('&amp;', '&', '\$2'), 0, 39) . ' ... ' . substr(str_replace('&amp;', '&', '\$2'), -10) : '\$2') . '</a><!-- w -->'";


These changes will make all url's created using the [url] bbcode to open in a new window and any plain text links after the change open in a new window. Any plain text links made before the second change will not open in a new window.


I dont even have a those lines of codes in includes/functions.php and it is the original RC1 code that I have.
azzurri
Registered User
 
Posts: 887
Joined: Fri Jul 21, 2006 7:48 pm

Re: Make links open in new window?

Postby karlsemple » Mon Jun 04, 2007 5:53 pm

Appears my suspicions were correct then, they have altered the way things work


*goes to examine the code*

What about the method Kevin posted?



EDIT: Actually a combination of the two seems to work

Find:
Code: Select all
$html   = "$whitespace<!-- $tag --><a$class href=\"$url\">$text</a><!-- $tag -->$append";



Replace With:
Code: Select all
$html   = "$whitespace<!-- $tag --><a$class target=\"_blank\" href=\"$url\">$text</a><!-- $tag -->$append";
Image
User avatar
karlsemple
Former Team Member
 
Posts: 39802
Joined: Mon Nov 01, 2004 8:54 am
Location: Hereford, UK

Re: Make links open in new window?

Postby azzurri » Mon Jun 04, 2007 6:34 pm

Karlsempe, that actually seems to work great! This is only applied to new URL:s without BBcode though, right?

A very big thank you.
azzurri
Registered User
 
Posts: 887
Joined: Fri Jul 21, 2006 7:48 pm

Re: Make links open in new window?

Postby karlsemple » Mon Jun 04, 2007 6:39 pm

azzurri wrote:Karlsempe, that actually seems to work great! This is only applied to new URL:s without BBcode though, right?

A very big thank you.



The bbcode change is in the bbcode.html and will work on any url posted using bbocdes.

but URI's such as this one http://www.phpbb.com only ones which are posted after the changes are made will work correctly and open in the new wndow :)
Image
User avatar
karlsemple
Former Team Member
 
Posts: 39802
Joined: Mon Nov 01, 2004 8:54 am
Location: Hereford, UK

Re: Make links open in new window?

Postby azzurri » Mon Jun 04, 2007 6:46 pm

You have done a great job. I am very greatful that you took the time to help others.
azzurri
Registered User
 
Posts: 887
Joined: Fri Jul 21, 2006 7:48 pm

Re: Make links open in new window?

Postby _Splinter » Tue Jun 05, 2007 7:27 pm

Kevin Clark wrote:This tutorial explains how too
http://www.easytutorials.org/phpbb3_pro ... indow.html


This example works perfectly. The only problem with it is that target="_blank" is no longer standards compliant.

If you want to keep it standards compliant then take a look at this post that I put on that sites support forum

http://www.stsoftware.biz/forum/showthread.php?p=980
_Splinter
Registered User
 
Posts: 44
Joined: Wed Oct 25, 2006 5:59 am
Location: Nottingham, England

Re: Make links open in new window?

Postby karlsemple » Wed Jun 06, 2007 4:31 am

_Splinter wrote:
Kevin Clark wrote:This tutorial explains how too
http://www.easytutorials.org/phpbb3_pro ... indow.html


This example works perfectly.



Edit the post with the links in you'll find as the earlier user did that editing the post messes up the links ;)
Image
User avatar
karlsemple
Former Team Member
 
Posts: 39802
Joined: Mon Nov 01, 2004 8:54 am
Location: Hereford, UK

Re: Make links open in new window?

Postby BigBlockMopar » Thu Jun 07, 2007 1:13 pm

Also emailadresses in posts wil get 'mailto:' added also.

testcase@mail.com will become mailto:testcase@mail.com


I *REALLY* hope this major SamePageLink-issue wil get fixed in the final release and let links open in new pages again.
Signatures are overrated...
User avatar
BigBlockMopar
Registered User
 
Posts: 76
Joined: Tue Mar 08, 2005 3:15 pm

Re: Make links open in new window?

Postby arod-1 » Thu Jun 07, 2007 3:55 pm

BigBlockMopar wrote:I *REALLY* hope this major SamePageLink-issue wil get fixed in the final release and let links open in new pages again.
i don't believe "fixed" is the right term here.
if there is any "bug" at all in this issue, it is the way links were handled in phpbb2, not the way they are handled in phpbb3.
when you have the target="_blank", users do not have a choice, and the link always opens in a new window.
when you omit it, users do have a choice: practically all existing browsers allow for opening of links in a new window or a new tab (for tab-supporting browses), by some key/click combination, when the user so choses.
IMO, letting the user decide is the "correct", or "more correct" thing to do.
it's true that this will take some getting used to, but ultimately, this is the direction the web is moving to, and that's why the standard no longer supports the target="_blank" attributre.
ultimately, your users will thank you for this change, which leaves the power in their hands.
eventually, the majority of sites will move (if they haven't already) to this more polite way of publishing links, and forcing a new window for links will be viewed more and more as rude. (i look at it like this now...)

just my 2c, of course.
arod-1
Registered User
 
Posts: 1307
Joined: Mon Sep 20, 2004 1:33 pm

Next

Return to phpBB Discussion

Who is online

Users browsing this forum: No registered users and 15 guests