Hi Walter,

thanks again for your great help.
It's on me that I didn't realize that myself.

This is with what I've come up now (with your help):

  function openLinksInNewWindow() {
    var newwindow =
getElementsByClassName(document.getElementById('content'), 'span',
'new-window');
    for (var i=0; i<newwindow.length; i++) {
      var ele = newwindow[i];
      var link = ele.getElementsByTagName('a')[0];
      if (link) link.setAttribute('target','_blank');
    };
  };
  addOnloadHook(openLinksInNewWindow);

(Be aware that there is some renaming involved ;-)


All the best,
Matthias

P.S.: I still wonder, why it didn't work with the new function where I
copied the call syntax from the webpage. Anyway, it's working now and I
don't care.


Am Fri, 5 Dec 2008 16:51:42 -0600
schrieb "Walter Mazza" <[EMAIL PROTECTED]>:

> Like I said... full of Fail today >< correct syntax (and I swear this
> time!)
> 
> var extlinks = getElementsByClassName(document, 'span', 'extlink');
> 
> replace 'span' with the name of the container tag (div, p, h3, etc)
> 
> Walter Mazza
> 
> 
> On Fri, Dec 5, 2008 at 4:46 PM, Walter Mazza <[EMAIL PROTECTED]>
> wrote:
> 
> > haha I guess I am full of fail today ><
> >
> > So it looks like the wikibits.js version of getElementsByClassName
> > requires you to specify the element/tag first THEN the class
> >
> > change
> > var extlinks = getElementsByClassName('extlink');
> > to
> > var extlinks = getElementsByClassName('span','extlink');
> >
> > replace 'span' with the name of the container tag (div, p, h3, etc)
> >
> > Never really noticed that as I replaced our wikibits.js function
> > with the latest version of this function(
> > http://www.robertnyman.com/2008/05/27/the-ultimate-getelementsbyclassname-anno-2008/)
> > which does not require us to specify the element/tag.
> >
> >
> > Walter Mazza
> >
> >
> >
> > On Fri, Dec 5, 2008 at 4:34 PM, Matthias Korn
> > <[EMAIL PROTECTED]>wrote:
> >
> >> Hi,
> >>
> >> trying your function gives me an error from the called function
> >> getElementsByClassName(). That is with the original one shipped
> >> with MediaWiki 1.13.0 as well as the new one from your link below.
> >>
> >> The error is
> >>
> >> 1) from the original function:
> >> Error: oElm.getElementsByTagName is not a function
> >> Source File:
> >> http://wiki.rockinchina.com/skins/common/wikibits.js?164 Line: 452
> >>
> >> which is the line (near to the beginning of that function):
> >>  var arrElements = (strTagName == "*" && oElm.all)? oElm.all :
> >> oElm.getElementsByTagName(strTagName);
> >>
> >> 2) from the new function:
> >> Error: elm.getElementsByClassName is not a function
> >> Source File:
> >>
> >> http://wiki.rockinchina.com/index.php?title=-&action=raw&smaxage=0&gen=js&useskin=ric
> >> Line: 152
> >>
> >> which is the line (near to the beginning of that function):
> >>  var elements = elm.getElementsByClassName(className),
> >>
> >>
> >> What am I doing wrong here?
> >> Thanks,
> >> Matthias
> >>
> >> P.S.: I am using Firefox 3, but some IE gave me the same problem.
> >>
> >>
> >> Am Fri, 5 Dec 2008 14:12:43 -0600
> >> schrieb "Walter Mazza" <[EMAIL PROTECTED]>:
> >>
> >> > 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
> >> >
> >>
> >>
> >> --
> >> Rock in China
> >> http://wiki.rockinchina.com/
> >> http://www.rockinchina.com/
> >>
> >> _______________________________________________
> >> 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
> 


-- 
Rock in China
http://wiki.rockinchina.com/
http://www.rockinchina.com/

_______________________________________________
MediaWiki-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l

Reply via email to