Javascript 在顶部窗口中捕获onkeydown

Javascript 在顶部窗口中捕获onkeydown,javascript,events,iframe,frameset,onkeydown,Javascript,Events,Iframe,Frameset,Onkeydown,我尝试在一个窗口中捕获onkeydown事件,该窗口包含一个包含多帧framset的iframe: top.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title> top.html </title> </head> <body> <iframe frameborder="0"

我尝试在一个窗口中捕获onkeydown事件,该窗口包含一个包含多帧framset的iframe:

top.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
  <title> top.html </title>
</head>
<body>
  <iframe frameborder="0" border="0" width="100%" height="100%" src="framset1.html" id="framset1"></iframe>
</body>

top.html
framset1.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
   "http://www.w3.org/TR/html4/frameset.dtd">
<HTML>
<HEAD>
<TITLE>A frameset document</TITLE>
</HEAD>
  <FRAMESET rows="66,*" border="0">
      <FRAME scrolling="no" id="frame1" name="frame1" src="frame1.html">
      <FRAME id="framset2" name="framset2" src="framset2.html">
  </FRAMESET>
</HTML>

框架集文档
framset2.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
   "http://www.w3.org/TR/html4/frameset.dtd">
<HTML>
<HEAD>
<TITLE>A frameset document</TITLE>
</HEAD>
  <FRAMESET cols="46,*" border="0">
      <FRAME scrolling="no" id="frame2" name="frame2" src="frame2.html">
      <FRAME id="frame3" name="frame3" src="frame3.html">
  </FRAMESET>
</HTML>

框架集文档
我想在frame3中捕获onkeydown事件。我发现了一个关于stackoverflow的相关问题,但没有成功应用

我必须继续走这条路吗?或者任何人都可以帮助我

谢谢


Paul

如果要在顶部框架中分配事件侦听器(
top.html
):

这仅在所有帧位于同一域+端口上时有效。否则,尝试访问
document.getElementById('framset1').contentDocument
时将出现安全异常


但是帧内帧内帧内帧。。。这就是你真正想要的吗?

谢谢你,鲁迪。你说得不对。。。帧内帧内帧内帧。。。很难看。我想在此旧应用程序上添加一些功能。替换的开发被延迟(我没有开发)。我需要更多的时间和方法来重构。我不能投票赞成你的答案。。。再次感谢
document.getElementById('framset1').contentDocument.getElementById('framset2').contentDocumentcontentDocument.getElementById('framset3').contentDocument.addEventListener('keydown', function(e) {
  alert('keydown in frame 700');
}, false);