从另一个页面控制Javascript计时器?

时间:2012-02-23 04:31:02

标签: javascript asp-classic

我正在尝试为我的应用程序创建一个自动注销页面。我正在使用Javascript来处理经典asp的计时器。我有三页js脚本页面,我调用js文件的主页,并使用OnLoad()启动计时器。 4秒后,弹出一个窗口,要求用户继续进行会话。但是当窗口弹出并且我在logout_alert.asp页面上单击是时,它不会更新主页上的计时器。如何让弹出窗口更新计时器?以下是脚本。

提前感谢您的帮助,

Frank G。

我有三页。对于此示例第1页,第2页和第3页。

第1页= logout_timeout.js


以下是此页面的脚本。

<!-- Begin

var c=0;
var t;

function ClockCount(){

c=c+1;
    //Show the clock value on the home page text field.
    document.timerform.clock.value = c;

if (c == 7) {
    //The user never responded so we will kill the session and log them out.
    alert("Your session has timed out you are logged out.");
    window.location.href = "logout.asp"
}
else if (c == 4) { 

    //We will popup a window to let the user know there about to be logged out.
    //This will give the user a chance to keep the session alive.
    logoutalert = window.open("logout_alert.asp", "logoutalert",    "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=420,height=145,left = 465,top = 250");
}

 //The timer will go round and round while recalling this function.
 t = setTimeout("ClockCount()",1000);

 }

 //Call to start the timer.
 function StartClock() {
 ClockCount();
 }

 //Called to stop the timer.
 function StopClock() {
 c=0 //Clear the timer.
 clearTimeout(t); //Stop it.
 }

 //  End -->

第2页= homepage.asp


此页面我将logout_timeout.js文件调用到。

 <script src="logout_timeout.js" type="text/javascript"></script>
 <body OnLoad="StartClock()">
 This will show our clock while its processing.
 <form id="timerform" name="timerform" method="post" action="">
   <input type="text" name="clock" id="clock" />
 </form>
 Used now just for testing!
   <input type="submit" name="continue" id="continue" value="START" onClick="StartClock()" />
   <input type="submit" name="continue" id="continue" value="STOP" onClick="StopClock()" />

第3页= logout_alert.asp


弹出此页面以通知用户他们即将被注销。

 <script src="logout_timeout.js" type="text/javascript"></script>
 <body>
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>
 <td class="Thread_Title">SESSION TIMEOUT  Alert!</td>
 </tr>
 <tr>
  <td width="85%" class="DataRows">Your session is about to timeout. Would you like to continue using WOTTS?</td>
 </tr>
 <tr>
  <td></td>
 </tr>
 <tr>
  <td></td>
 </tr>
 <tr>
  <td><form id="timerform" name="timerform" method="post" action="">
 <input type="text" name="clock" id="clock" />
 </form></td>
 </tr>
 <tr>
  <td>
   <input type="submit" name="continue" id="continue" value="START" onClick="StartClock()" />
 <input type="submit" name="continue" id="continue" value="STOP" onClick="StopClock()" />   </td>
  </tr>
  </table>

1 个答案:

答案 0 :(得分:2)

你错过了一块拼图:对另一个窗口的引用。某些安全限制沙箱将窗口对象分开,除非它们是从现有窗口生成的。如果你使用JavaScript的window.open()函数,你的新窗口将打开一个打开它的父窗口的句柄。然后,在脚本中,您可以利用该句柄来操作对象和行为,并在父窗口中执行函数。这将它们联系在一起。

这里有很多例子:

Can I pass a JavaScript variable to another browser window?