How can I attach an Event to an element of a parent frame in javascript?

375 Views Asked by At

I want to attach an 'onclick' event in a link element in my editor.

I did this:

parent.document.frames["myframe"].document.body.attachEvent('onmouseover', function(e) { 
        parent.document.frames["myframe"].document.getElementsByTagName("a").attachEvent('onclick', function(e) { 
            alert("Hello");
        });
 });

but it doesn't work. I want this one to work in IE and I am using Javascript. Does anyone know what is wrong with it?

Thanks

2

There are 2 best solutions below

0
On BEST ANSWER

I did with jQuery finally:

  parent.document.frames["myframe"].document.body.attachEvent('onmouseover', function(e) { 
        $("a",parent.document.frames["myframe"].document).click(function(event){
             alert("hello");
        });
  });
1
On

Try attaching the mouseover event to a surrounding div rather then the body.