0

I try to capture onkeydown event in a window wich contains a iframe containing mutliple 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>

I want to capture event onkeydown in frame3. I have found a relative question on stackoverflow here but applied without succes.

Do i have to continue on this way or anyone can help me.

Thanks.

Paul

Community
  • 1
  • 1

1 Answers1

0

If you want to assign the event listener in the top frame (top.html):

document.getElementById('framset1').contentDocument.getElementById('framset2').contentDocumentcontentDocument.getElementById('framset3').contentDocument.addEventListener('keydown', function(e) {
  alert('keydown in frame 700');
}, false);

This only works if all frames are on the same domain + port. Otherwise you'll get a security exception trying to access document.getElementById('framset1').contentDocument.

But frames within frames within frames... Is that what you really want??

Rudie
  • 52,220
  • 42
  • 131
  • 173
  • Thanks Rudie. You're off course right ... frames within frames within frames ... it's ugly. I want to add some features on this old application. The development of the replacement is delayed (which I do not develop). I need more time and means for refactoring. I can't vote for your answer ... thanks again – Paul Koenig Apr 25 '11 at 09:38