[ToolKit] External links in new window

phpBB SEO mods by phpBB SEO.

Moderator: Moderators

[ToolKit] External links in new window

Postby dcz » Sun Nov 09, 2008 1:56 pm

External links in new window

NOTE : SEO premod User shall not use this trick, it's included in the premod with even more advanced options.

Here is a very simple yet complete method to have external links opened in a new window (or tab depending on the browser).

The only way to achieve this while staying valid XHTML sctrict is to use javascript. Most of the existing method will modify the way links are build in the php script to add the javascript required, which is adding useless weight to the page and implies to mod all places where external links can be built for the solution to be complete.

This method will be made of a single javascript function addition which will have the browser to do the job and dynamically add the required code to open all external links in new windows at once.

Simple and efficient, this method can be easily used on every web page.

Open :
Code: Select all
style/prosilver/template/forum_fn.js

Add at the end of the file :
Code: Select all
// www.phpBB-SEO.com SEO TOOLKIT BEGIN
// Open external links in new window in a XHTML 1.x compliant way.
function nw_external() {
   var current_domain = document.domain;
   if (!current_domain || !document.getElementsByTagName) return;
   var hrefels = new Array;
   var hrefelslen = 0;
   var hrefinner = '';
   hrefels = document.getElementsByTagName("a");
   hrefelslen = hrefels.length;
   for (var i = 0; i < hrefelslen; i++) {
      hrefinner = hrefels[i].innerHTML.toLowerCase();
      if ( (hrefels[i].href == '') || (hrefels[i].href.indexOf('javascript') >=0 ) || (hrefinner.indexOf('<a') >= 0) || (hrefels[i].href.indexOf(current_domain) >= 0) || hrefels[i].onclick != null) {
         continue;
      }
      hrefels[i].onclick = function () { window.open(this.href); return false; };
   }
}
onload_functions.push('nw_external()');
// www.phpBB-SEO.com SEO TOOLKIT END


For subsilver2, in :

Code: Select all
style/subsilver2/template/overall_header.html

Add :
Code: Select all
<script language="Javascript" type="text/javascript">
// <![CDATA[
// www.phpBB-SEO.com SEO TOOLKIT BEGIN
// Open external links in new window in a XHTML 1.x compliant way.
window.onload = function() {
   var current_domain = document.domain;
   if (!current_domain || !document.getElementsByTagName) return;
   var hrefels = new Array;
   var hrefelslen = 0;
   var hrefinner = '';
   hrefels = document.getElementsByTagName("a");
   hrefelslen = hrefels.length;
   for (var i = 0; i < hrefelslen; i++) {
      hrefinner = hrefels[i].innerHTML.toLowerCase();
      if ( (hrefels[i].href == '') || (hrefels[i].href.indexOf('javascript') >=0 ) || (hrefinner.indexOf('<a') >= 0) || (hrefels[i].href.indexOf(current_domain) >= 0) || hrefels[i].onclick != null) {
         continue;
      }
      hrefels[i].onclick = function () { window.open(this.href); return false; };
   }
}
// www.phpBB-SEO.com SEO TOOLKIT END
// ]]>
</script>

Before :
Code: Select all
</head>


Note that the subsilver2 code change will work on any html page, but you'll may have to deal with calling window.onload more than once in case it is already used.
Prosilver provides with a nice method to perform multiple calls to window.onload.

Support for this trick is provided in this thread.
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21382
Joined: Fri Apr 28, 2006 9:03 pm

Advertisement

Postby dcz » Tue Jan 13, 2009 1:52 pm

First post updated, replaced :
Code: Select all
if ( (hrefels[i].href == '') || (hrefinner.indexOf('<a') >= 0) || (hrefels[i].href.indexOf(current_domain) >= 0) ) {

with :
Code: Select all
if ( (hrefels[i].href == '') || (hrefels[i].href.indexOf('javascript') >=0 ) || (hrefinner.indexOf('<a') >= 0) || (hrefels[i].href.indexOf(current_domain) >= 0) ) {


in each theme's modified files.

This is to allow the usage of href="javascript links in the page.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21382
Joined: Fri Apr 28, 2006 9:03 pm

Re: [ToolKit] External links in new window

Postby wwwmaster » Thu Sep 17, 2009 7:16 am

I think it is better to match on those a tags that use the postlink or postlink-local class. This works on styles that use postlink or postlink-local as the class for links. This code is more accurate on targetting the specific links:

Code: Select all
// http://www.phpBB-SEO.com SEO TOOLKIT BEGIN
// Open external links in new window in a XHTML 1.x compliant way.
function nw_external() {
   var hrefels = new Array;
   var hrefelslen = 0;
   hrefels = document.getElementsByTagName("a");
   hrefelslen = hrefels.length;
   for (var i = 0; i < hrefelslen; i++) {
      if ( hrefels[i].className == 'postlink' || hrefels[i].className == 'postlink-local' ) {
         hrefels[i].onclick = function () { window.open(this.href); return false; };
      }
   }
}
onload_functions.push('nw_external()');
// http://www.phpBB-SEO.com SEO TOOLKIT END
Last edited by wwwmaster on Thu Sep 17, 2009 6:43 pm, edited 2 times in total.
wwwmaster
 
Posts: 22
Joined: Sat Mar 10, 2007 9:07 pm

Re: [ToolKit] External links in new window

Postby iwanttobelieve » Thu Sep 17, 2009 11:19 am

You can also use mootool for this, which is not an overkill :lol:

You just add a rel="external" and have mootool does the job, about 1 line of javascript I think.
iwanttobelieve
PR1
PR1
 
Posts: 123
Joined: Sun Jun 14, 2009 5:37 am
Location: Somewhere I don't belong lol

Re: [ToolKit] External links in new window

Postby wwwmaster » Thu Sep 17, 2009 6:07 pm

The problem in phpBB3 is that you have to make several non-trivial modifications in order to add that rel="external" to the links.
wwwmaster
 
Posts: 22
Joined: Sat Mar 10, 2007 9:07 pm

Re: [ToolKit] External links in new window

Postby iwanttobelieve » Fri Sep 18, 2009 1:21 am

And that is why we have Prime Link :lol:
iwanttobelieve
PR1
PR1
 
Posts: 123
Joined: Sun Jun 14, 2009 5:37 am
Location: Somewhere I don't belong lol

Re: [ToolKit] External links in new window

Postby wwwmaster » Sat Sep 19, 2009 1:53 am

Then again, the problem with Prime Link is that it cannot doesn't "magic links" in existing posts on the board, as it requires modifying the posts' text in database. The solution presented above affects all links, existing and new links.

Anyway, Prime Link looks like a nice MOD.
wwwmaster
 
Posts: 22
Joined: Sat Mar 10, 2007 9:07 pm

Re: [ToolKit] External links in new window

Postby dcz » Sat Sep 19, 2009 12:03 pm

wwwmaster wrote:I think it is better to match on those a tags that use the postlink or postlink-local class. This works on styles that use postlink or postlink-local as the class for links.

Not necessarily, doing this goes down to the same behavior as prime link, but without increasing the server work (since it's here the client to do it), and some could want to see all external url dealt with directly, as the original code is doing.

About the rel="external", you could use this same function to dynamically add it if you prefer, but the main point when writing this was to provide with a simple standalone solution that would work in all cases.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21382
Joined: Fri Apr 28, 2006 9:03 pm

Re: [ToolKit] External links in new window

Postby Professional » Sun Sep 20, 2009 1:45 pm

thank u,does it have effect on seo?
انجمن تخصصی نسل جدید موبایل ها-Apple Portal
My Handwritings: Professional Dreams
Every Thing That U Feel,Is Every Thing That I Feel.
User avatar
Professional
PR5
PR5
 
Posts: 550
Joined: Mon Apr 07, 2008 5:41 am
Location: 1/2 of the World

Re: [ToolKit] External links in new window

Postby dcz » Tue Sep 22, 2009 8:56 am

Small update, the code will now preserve pre-existing onclick (if any) on links.

The code change is to replace :
Code: Select all
      if ( (hrefels[i].href == '') || (hrefels[i].href.indexOf('javascript') >=0 ) || (hrefinner.indexOf('<a') >= 0) || (hrefels[i].href.indexOf(current_domain) >= 0)) {
         continue;
      }

with :
Code: Select all
      if ( (hrefels[i].href == '') || (hrefels[i].href.indexOf('javascript') >=0 ) || (hrefinner.indexOf('<a') >= 0) || (hrefels[i].href.indexOf(current_domain) >= 0) || hrefels[i].onclick != null) {
         continue;
      }


;)
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21382
Joined: Fri Apr 28, 2006 9:03 pm

Re: [ToolKit] External links in new window

Postby benwick » Wed Oct 14, 2009 5:29 pm

How to effect the website links on the member pages with this? :)
benwick
 
Posts: 2
Joined: Wed Oct 14, 2009 5:18 pm

Re: [ToolKit] External links in new window

Postby dcz » Sun Oct 18, 2009 8:34 am

Well, it does alter all external links in phpBB at once, even on profiles ones. What do you mean more precisely ?
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21382
Joined: Fri Apr 28, 2006 9:03 pm

Re: [ToolKit] External links in new window

Postby benwick » Sun Oct 18, 2009 9:44 am

Oh sorry! I just have clicked on my site in the member list. And hence my site ist hosting the forum, it was loaded in the same window. :roll: You're right, the mod is functioning with all external links! Great mod, by the way! :D
benwick
 
Posts: 2
Joined: Wed Oct 14, 2009 5:18 pm

Re: [ToolKit] External links in new window

Postby Gisher » Sun Nov 29, 2009 1:02 am

Before 0.6.2 verison I use mod prime links with go.php
Code: Select all
<?php
if (isset($_SERVER['QUERY_STRING'])) Header('Location: '.$_SERVER['QUERY_STRING']);
?>
and then block this file in robots.txt
Code: Select all
Disallow: /go.php


How can I disable indexing external links for robots?
Gisher
PR0
PR0
 
Posts: 83
Joined: Sat Sep 27, 2008 8:54 am

Re: [ToolKit] External links in new window

Postby dcz » Sat Dec 05, 2009 8:42 am

NOTE : SEO premod User shall not use this trick, it's included in the premod with even more advanced options.


;)
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21382
Joined: Fri Apr 28, 2006 9:03 pm

Next

Return to phpBB SEO TooLKit

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 6 guests