查看文章 |
[转]对框架页面超时监听
2008-09-13 21:47
但是对于框架页面,如何处理?例如需要对下面一个简单的框架页面进行监听: <frameset rows="80,*" cols="*" frameborder="no" border="0" framespacing="0"> <frame src="top.htm" name="topFrame" scrolling="No" noresize="noresize" id="topFrame" /> <frameset cols="80,*" frameborder="no" border="0" framespacing="0"> <frame src="left.htm" name="leftFrame" scrolling="No" noresize="noresize" id="leftFrame" /> <frame src="main.htm" name="mainFrame" id="mainFrame" /> </frameset> </frameset> 该框架有3个frame,当用户在任意一个框架区域发生操作都能够被监听到。如何实现? 这里推荐借助JQuery库的来实现,JQuery详细的使用方法请登录http://jquery.com/ 具体实现如下: 在top.htm中编写"计时监听"程序和"监听框架各个区域动作"程序: <script type="text/javascript" src="../js/jquery.js"></script> //导入jQuery库文件 <script type="text/javascript"> var maxTime = 300; //最大计时值为300S var timeOutValue = maxTime; function timeListener() { timeOutValue = timeOutValue - 1; if(timeOutValue<=0) { timeOutValue = maxTime; alert("尊敬的用户,您已经"+ maxTime/60 + " 分钟没有操作..."); } setTimeout("timeListener()",1000); //每隔一秒监听一次 } /** *页面初始化时加载计时监听程序 */ $(document).ready(function() { timeListener(); }); /** *监听topFrame区域的各种动作,一旦有动作发生,就重新计时 / $(window.parent.topFrame).blur(function() { timeOutValue = maxTime; }).click(function() { timeOutValue = maxTime; }).dblclick(function() { timeOutValue = maxTime; }).focus(function() { timeOutValue = maxTime; }).keydown(function() { timeOutValue = maxTime; }).keypress(function() { timeOutValue = maxTime; }).mousedown(function() { timeOutValue = maxTime; }).mousemove(function() { timeOutValue = maxTime; }).mouseover(function() { timeOutValue = maxTime; }).scroll(function() { timeOutValue = maxTime; }); /** *监听leftFrame区域的各种动作,一旦有动作发生,就重新计时 / $(window.parent.leftFrame).blur(function() { timeOutValue = maxTime; }).click(function() { timeOutValue = maxTime; }).dblclick(function() { timeOutValue = maxTime; }).focus(function() { timeOutValue = maxTime; }).keydown(function() { timeOutValue = maxTime; }).keypress(function() { timeOutValue = maxTime; }).mousedown(function() { timeOutValue = maxTime; }).mousemove(function() { timeOutValue = maxTime; }).mouseover(function() { timeOutValue = maxTime; }).scroll(function() { timeOutValue = maxTime; }); /** *监听mainFrame区域的各种动作,一旦有动作发生,就重新计时 / $(window.parent.mainFrame).blur(function() { timeOutValue = maxTime; }).click(function() { timeOutValue = maxTime; }).dblclick(function() { timeOutValue = maxTime; }).focus(function() { timeOutValue = maxTime; }).keydown(function() { timeOutValue = maxTime; }).keypress(function() { timeOutValue = maxTime; }).mousedown(function() { timeOutValue = maxTime; }).mousemove(function() { timeOutValue = maxTime; }).mouseover(function() { timeOutValue = maxTime; }).scroll(function() { timeOutValue = maxTime; }); </script> |
最近读者:

