[Mediawiki-l] Make internal links open in a new tab

Matthias Korn matsch at rockinchina.com
Fri Dec 5 20:02:56 UTC 2008


Hi,

Am Fri, 5 Dec 2008 12:20:50 -0600
schrieb "Walter Mazza" <wjmazza at gmail.com>:

[..]
> Code for [[Template:ExtLink]]: (new page)
> <span class="extlink">[[{{{1}}}]]</span>
> 
> Code for [[MediaWiki:Common.js]]: ("append" to page)
> function ExtLinks() {
> var extlinks = getElementsByClassName('extlink');
> for (var i=0, il=extlinks.length; i<il; i++) {
> extlinks[i].setAttribute('target','_blank');
> };
> };
> addOnloadHook(ExtLinks);
> 
> Now whenever we want to make a interwiki link open in a new window,
> we just use {{ExtLink|Special:Upload}}
> 
> the function getElementsByClassName should already be defined in the
> wikibits.js file but if for some reason it is not available, you can
> get the updated version at
> http://www.robertnyman.com/2008/05/27/the-ultimate-getelementsbyclassname-anno-2008/

I tried your JavaScript function, which seemed the way to go for me
(just without the template around it). But, somehow, it is not working.

Yes, I force reloaded.
Yes, I have getElementsByClassName.

The method seems to be executed onLoad (I inserted an alert()), but
links still open in the same window. Also, while looking at the method:
isn't it rather adding the target-attribute to the span-tag than to
the link itself? Without trying it, this seems suspicious.

I also checked the DOM (with Firebug) and the target-attribute of the
link is empty (don't know if it should be there though).

Thanks for your help,
Matthias



More information about the MediaWiki-l mailing list