在顶部窗口中捕获onkeydown

| 我尝试在一个包含iframe的窗口中捕获onkeydown事件,该iframe包含多个framset: 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>
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的相对问题,但没有成功应用。 我是否必须继续这种方式,否则任何人都可以帮助我。 谢谢。 保罗     
已邀请:
如果要在顶部框架(
top.html
)中分配事件监听器:
document.getElementById(\'framset1\').contentDocument.getElementById(\'framset2\').contentDocumentcontentDocument.getElementById(\'framset3\').contentDocument.addEventListener(\'keydown\', function(e) {
  alert(\'keydown in frame 700\');
}, false);
仅当所有帧都在同一域+端口上时,此方法才有效。否则,尝试访问
document.getElementById(\'framset1\').contentDocument
时会出现安全异常。 但是,帧内的帧内……是您真正想要的吗?     

要回复问题请先登录注册