Forums

Unfortunately no one can be told what FluxBB is - you have to see it for yourself.

You are not logged in.

#1 2012-12-27 13:31:06

glennvho
Member
Registered: 2012-12-07
Posts: 10
Website

Open hyperlink in new tab or window

Is it possible to open links by default in a new tab or window?

I want my forum to have hyperlinks that open by default in a new tab or windows so users don't exit the topic the're in.

Offline

#2 2012-12-27 15:53:19

sklerder
Member
From: Brittany
Registered: 2012-11-06
Posts: 130
Website

Re: Open hyperlink in new tab or window

Hello.

Yes, it's possible smile
One solution is to modify the "[url]" BBcode so that it appends/prepends a <target="_blank"> to the link ...

Offline

#3 2012-12-28 12:02:11

Squiggles
Member
Registered: 2012-12-14
Posts: 278

Re: Open hyperlink in new tab or window

I would like to do this also, can you provide detailed instructions on how to do this? Like what file to edit etc

Offline

#4 2012-12-28 17:02:13

sklerder
Member
From: Brittany
Registered: 2012-11-06
Posts: 130
Website

Re: Open hyperlink in new tab or window

Hello.

The essential file, if you want to do it is "include/parser.php".

In "function handle_url_tag", you should find :

return '<a href="'.$full_url.'">'.$link.'</a>';

Replace it by :

return '<a target="_blank" href="'.$full_url.'">'.$link.'</a>';

This should do the trick for most of the links you want to open in a separate tab or window.

Offline

#5 2012-12-28 17:18:49

Otomatic
FluxBB Donor
From: Paris - France
Registered: 2010-01-26
Posts: 576
Website

Re: Open hyperlink in new tab or window

Hi,

<a target="_blank" 

is not XHTML strict.

return '<a href="'.$full_url.'" onclick="window.open(this.href); return false;">'.$link.'</a>';

is XHTML strict.


Ce n'est pas parce que l'erreur se propage qu'elle devient vérité. Ghandi
An error does not become truth by reason of multiplied propagation. Ghandi

Offline

#6 2012-12-28 17:39:10

sklerder
Member
From: Brittany
Registered: 2012-11-06
Posts: 130
Website

Re: Open hyperlink in new tab or window

Hi, Otomatic.

Nice to know, I didn't verify !
Thanks smile

It means that Javascript must absolutely been activated to work, then hmm

Offline

#7 2013-02-19 20:21:34

raygene
Member
From: QC, Canada
Registered: 2012-11-02
Posts: 57
Website

Re: Open hyperlink in new tab or window

Thanks, that's exactly what I was looking for.

One question though, the code was slightly changed at one point to include " rel="nofollow":

return '<a href="'.$full_url.'" rel="nofollow">'.$link.'</a>';

Where should I insert it in:

return '<a href="'.$full_url.'" onclick="window.open(this.href); return false;">'.$link.'</a>';

Thanks.


Never, under any circumstances, take a laxative and a sleeping pill on the same night...

Offline

#8 2013-02-19 22:06:52

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,728
Website

Re: Open hyperlink in new tab or window

Like this, for example:

return '<a href="'.$full_url.'" rel="nofollow" onclick="window.open(this.href); return false;">'.$link.'</a>';

fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

#9 2013-02-19 22:20:08

raygene
Member
From: QC, Canada
Registered: 2012-11-02
Posts: 57
Website

Re: Open hyperlink in new tab or window

Thanks, Franz, I'm learning a lot from you guys.


Never, under any circumstances, take a laxative and a sleeping pill on the same night...

Offline

#10 2013-02-19 22:50:28

Franz
Lead developer
From: Germany
Registered: 2008-05-13
Posts: 6,728
Website

Re: Open hyperlink in new tab or window

You're welcome. And that is good to hear, don't be afraid to ask! smile


fluxbb.de | develoPHP

"As code is more often read than written it's really important to write clean code."

Offline

Board footer

Powered by FluxBB