2011-04-24 51 views
0

我試圖捕捉onKeyDown事件在一個窗口至極含有含複式framset一個IFRAME:捕獲的onkeydown在上面的窗口

的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 here的相關問題,但是沒有成功應用。

我必須繼續這樣或任何人都可以幫助我。

謝謝。

保羅

回答

0

如果你想在頂部框架(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

但幀內幀的幀......這是你真正想要的嗎?

+0

謝謝Rudie。你偏離正確的軌道......幀內的幀內幀......這很醜陋。我想在這個舊的應用程序中添加一些功能。替代品的開發延遲了(我不發展)。我需要更多時間和手段進行重構。我不能爲您的答案投票...再次感謝 – 2011-04-25 09:38:02