HTML中用了frameset ,如何在整个IE中捕获键盘事件?
HTML中可以用JAVASCRIPT,但不能用ASP等。我用的只是HTML。下面是我的index.html<frameset rows="100,180,*" cols="*" frameborder="no" border="0" framespacing="0" style="height:1500px;">
<frame src="head01.HTM" name="topFrame" scrolling="no" noresize="noresize" id="topFrame" />
<frame src="head02.HTM" name="top2Frame" scrolling="no" id="top2Frame" />
<frame src="Main.HTM" name="mainFrame" scrolling="No" noresize="noresize" id="mainFrame" />
<noframes>
</noframes>
</frameset> 现在,mainFrame是根据topFrame上面的链接动态生成的。所以,mainFrame中显示的HTML不能写JS代码,
怎么样在index.html中写JS,在整个IE中捕获键盘事件?
也就是说,我想要这样的结果:不论焦点在哪个frame中,我按下热键F8后,都alert('F8');
HTML中可以用JAVASCRIPT,但不能用ASP等。我用的只是HTML。下面是我的index.html<frameset rows="100,180,*" cols="*" frameborder="no" border="0" framespacing="0" style="height:1500px;">
<frame src="head01.HTM" name="topFrame" scrolling="no" noresize="noresize" id="topFrame" />
<frame src="head02.HTM" name="top2Frame" scrolling="no" id="top2Frame" />
<frame src="Main.HTM" name="mainFrame" scrolling="No" noresize="noresize" id="mainFrame" />
<noframes>
</noframes>
</frameset> 现在,mainFrame是根据topFrame上面的链接动态生成的。所以,mainFrame中显示的HTML不能写JS代码,
怎么样在index.html中写JS,在整个IE中捕获键盘事件?
也就是说,我想要这样的结果:不论焦点在哪个frame中,我按下热键F8后,都alert('F8');
<script language="javascript">
function hello(){
alert("hello mouse click !");
}
window.onload=function(){
for(var i=0;i<frames.length;i++){
frames[i].document.onclick = hello;
}
}
</script> <frameset rows="100,180,*" cols="*" frameborder="no" border="0" framespacing="0" style="height:1500px;">
<frame src="head01.HTM" name="topFrame" scrolling="no" noresize="noresize" id="topFrame" />
<frame src="head02.HTM" name="top2Frame" scrolling="no" id="top2Frame" />
<frame src="Main.HTM" name="mainFrame" scrolling="No" noresize="noresize" id="mainFrame" /> <noframes>
</noframes>
</frameset>
</html>
改一下再发。
<html>
<script language="javascript">
function hello(){
alert("hello key down !");
}
window.onload=function(){
document.onkeydown = hello;
for(var i=0;i<frames.length;i++){
frames[i].document.attachEvent("onkeydown", hello);
}
}
</script> <frameset rows="100,180,*" cols="*" frameborder="no" border="0" framespacing="0" style="height:1500px;">
<frame src="head01.HTM" name="topFrame" scrolling="no" noresize="noresize" id="topFrame" />
<frame src="head02.HTM" name="top2Frame" scrolling="no" id="top2Frame" />
<frame src="Main.HTM" name="mainFrame" scrolling="No" noresize="noresize" id="mainFrame" /> <noframes>
</noframes>
</frameset>
</html