开发者

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

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

I did this:

parent.docu开发者_Go百科ment.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


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


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");
        });
  });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜