window.frames[0].document.onkeydown 在 Firefox 中不起作用
我这条线在 Firefox 中不起作用(在 IE 和 Chrome 中工作得很好),
ste.frame.document.onkeydown=function(e) {
alert('a');
};
这里 ste.frame 是一个窗口对象 [object Window]。我尝试
window.frames[0].document.onkeydown=function(e){
alert('b');
}
在 IE 和 Chrome 中工作,但在 Firefox 中不起作用。我想如果第二个有效,第一个也可以。
有谁知道如何解决这个问题? 提前致谢。
I have this line not working in Firefox (works perfectly fine in IE and Chrome)
ste.frame.document.onkeydown=function(e) {
alert('a');
};
here ste.frame is a window object [object Window]. I tried
window.frames[0].document.onkeydown=function(e){
alert('b');
}
Also working in IE and Chrome and not working in Firefox. I guess if the second one works, the first one will work either.
Does anyone know how to resolve this?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在上面的评论中发布的代码不起作用,因为您在子框架加载其 about:blank 文档之前设置侦听器。因此,您要在临时文档上设置一个侦听器,然后该侦听器就会消失。
既然 HTML5 规范实际上定义了 about:blank 的行为方式,Gecko 可能会在某个时候改变这里的行为,以更接近您在 IE 和 WebKit 中看到的内容。
The code you posted in the comments above doesn't work because you're setting the listener before the subframe is done loading its about:blank document. So you're setting a listener on a temporary document that then goes away.
Gecko is likely to change behavior here at some point to more closely match what you see in IE and WebKit now that the HTML5 spec actually defines how about:blank should behave....
我花了将近一个小时来找到解决方案,但我找不到。我认为原因是 Mozilla 基金会仅实现了 IFrame 对象的基础知识,因此您无法分配事件处理程序。与事件处理程序相比,您可以修改 css 样式(请参阅此示例)。
我使用 DOM-Inspector 来确定该代码指向哪个对象 在我看来,它指向Firefox的DOM全局对象。
PS:如有错误,请指正。
I spended almost an hour to find a solution, but I couldn't. I think the reason is, that the Mozilla foundation has implented just the basics of IFrame object, so you can't assign an eventhandler. Compare to eventhandler you can modify css styles (see this example).
I used the DOM-Inspector to figure out on which object this code does point. In my eyes, it points to global object of DOM of Firefox.
PS: In case I'm wrong, correct me please.