Hi Justin,

You can also use the simpler event model and add the event as follows:

anchor.onclick = function(){
  alert('anchor with rel clicked');
}

This works in both IE and Mozilla.

For more info on events in javascript the best resource I've found is
http://www.quirksmode.org

Cheers,
Mark

On Thu, 19 Aug 2004 10:06:28 +0300, Eser 'Laroux' <[EMAIL PROTECTED]> wrote:
> You can use attachEvent method for this. But it's supported by Internet
> Explorer 6 only.
> 
> --
> <a href="about:mozilla" rel="help">test</a>
> 
> <script type="text/javascript">
>         var anchors = document.getElementsByTagName('a');
>         for (var i=0; i<anchors.length; i++) {
>                 var anchor = anchors[i];
>                 if (anchor.getAttribute('rel') == 'help') {
>                         anchor.attachEvent(
>                                 'onclick',
>                                 function() {
> window.open(event.srcElement.getAttribute('href'),'popupwindow','width=400,h
> eight=400,scrollbars=1,resizable=1'); return false; }
>                         );
>                 }
>         }
> </script>
> 
> 
> > -----Original Message-----
> > Here's a function:
> >
> > function helpLinks()
> >       {
> >       if(!document.getElementsByTagName) return;
> >       var anchors = document.getElementsByTagName("a");
> >       for (var i=0; i<anchors.length; i++)
> >               {
> >               var anchor = anchors[i];
> >               if (anchor.getAttribute("href") &&
> anchor.getAttribute("rel")
> > ==
> > "help")
> >                       {
> >                       anchor.setAttribute(
> > "onclick","window.open(this.href,'popupwindow','width=400,height=400,scr
> > ollbars,resizable'); return false;",0);
> >                       }
> >               }
> >       }
> >
> > It works perfectly well in everything I can get my hands on except for
> > IE, where it fails to set the onclick event to all A elements with a
> > rel attribute of 'help'.
> >
> > Changing anchor.setAttribute(...) to
> > anchor.setAttribute('target','_blank',0); DOES work (the link opens in
> > a new window), so it would appear that IE doesn't like setting onlick
> > attributes this way.
> >
> > Can anyone either:
> > - suggest an alternate way to achieve this, or
> > - suggest a good mailing list to seek further help on (like a DOM list)
> 
> ******************************************************
> The discussion list for  http://webstandardsgroup.org/
> 
> Proud presenters of Web Essentials 04 http://we04.com/
>  Web standards, accessibility, inspiration, knowledge
> To be held in Sydney, September 30 and October 1, 2004
> 
>  See http://webstandardsgroup.org/mail/guidelines.cfm
>  for some hints on posting to the list & getting help
> ******************************************************
> 
>
******************************************************
The discussion list for  http://webstandardsgroup.org/

Proud presenters of Web Essentials 04 http://we04.com/
 Web standards, accessibility, inspiration, knowledge
To be held in Sydney, September 30 and October 1, 2004

 See http://webstandardsgroup.org/mail/guidelines.cfm
 for some hints on posting to the list & getting help
******************************************************

Reply via email to