开发者

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

开发者 https://www.devze.com 2023-01-30 17:05 出处:网络
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) {

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

精彩评论

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