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.

English |
French




