oh my! deepest apologies ><
I quickly typed up that code instead of copy/pasting from our JS file cause
I also have other code in this function I didn't want to add :P Here is the
updated code.
function ExtLinks() {
var extlinks = getElementsByClassName('extlink');
for (var i=0, il=extlinks.length; i<il; i++) {
var ele = extlinks[i];
var link = ele.getElementsByTagName('a')[0];
if (link) link.setAttribute('target','_blank');
};
};
addOnloadHook(ExtLinks);
And yes, it runs on page load because we need it to run after the elements
are loaded. :) let me know if it doesnt work.
@ Platonides:
Thanks for pointing that out! I must have overlooked that variable
Walter Mazza
On Fri, Dec 5, 2008 at 2:02 PM, Matthias Korn <[EMAIL PROTECTED]>wrote:
> Hi,
>
> Am Fri, 5 Dec 2008 12:20:50 -0600
> schrieb "Walter Mazza" <[EMAIL PROTECTED]>:
>
> [..]
> > 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
>
> _______________________________________________
> MediaWiki-l mailing list
> [email protected]
> https://lists.wikimedia.org/mailman/listinfo/mediawiki-l
>
_______________________________________________
MediaWiki-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l