P
P
pratamishus2012-01-09 13:49:54
Mozilla Firefox
pratamishus, 2012-01-09 13:49:54

Window.frames[0].document.onkeydown not working in Firefox?

Hello people!
I'm dying here trying to figure out what the problem is. I have a code

ste.frame.document.onkeydown=function(e) {<br/>
 alert('a');<br/>
};

Here ste.frame is [object Window]. That is, it is almost identical to this:
window.frames[0].document.onkeydown=function(e){<br/>
 alert('a');<br/>
}

The code works in IE and Chrome but doesn't want to work in Firefox. When I tested in jsfiddle.net, the event is processed, but not directly. Here is the code for the test:
&lt;iframe&gt;&lt;/iframe&gt;<br/>
&lt;script type=&quot;text/javascript&quot;&gt;<br/>
 window.frames[0].document.onkeydown=function(e){<br/>
 alert('a');<br/>
 }<br/>
&lt;/script&gt;

Google did not give anything - has anyone met with this or maybe knows what needs to be done to make FF work out this event?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jazzz13, 2012-01-09
@pratamishus

I have it working like this:

document.addEventListener('DOMContentLoaded', function(){

  window.frames[0].document.onkeydown=function(e){

    alert('a');

  };
  
});

P
pratamishus, 2012-01-09
@pratamishus

Thanks - both options work, but not in the code of the desired plugin. Solved the problem in a different way :).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question