尝试刷新部分,然后出错



我正在构建一个站点,管理层的任何人都可以访问不同商店中的安全摄像头。 我使用 iframe 构建,以便经理可以选择他们想要的商店。 一旦他们选择了商店,我希望页面每 6 秒刷新一次,但在 3 分钟后出错。 这将防止连续流式传输数据。

所以这就是我所拥有的,但有些地方不对劲

<title>Store #1901(low-rez)</title>
<center><font color ="blue">Store 1901 (<b>Medium</b> / <a    href="tiny.html">Small</a>)</center>

<iframe src="cam1.html" width="380" height="295" frameborder="0" >
</iframe>
<iframe src="cam2.html" width="380" height="295" frameborder="0" >
</iframe>
<iframe src="cam3.html" width="380" height="295" frameborder="0" >
</iframe>
<iframe src="cam4.html" width="380" height="295" frameborder="0" >
</iframe>
<iframe src="cam5.html" width="380" height="295" frameborder="0" >
</iframe>
<iframe src="cam6.html" width="380" height="295" frameborder="0" >
</iframe>
<iframe src="cam7.html" width="380" height="295" frameborder="0" >
</iframe>
<iframe src="cam8.html" width="380" height="295" frameborder="0" >
</iframe>
<iframe src="cam10.html" width="380" height="295" frameborder="0" >
</iframe>
<script type="text/javascript">
var intervalID = 0;
function windowOnInitialize()
{
intervalID = setInterval("refresh()", 6000);
//alert("we were called");
}
var counter = 0;
function refresh()
{
//alert("we got to if statement");
if (counter < 50)
{
    counter++;
    //alert(counter);
    document.getElementById("theId").src="small.html" + Math.random();
 }
else
{
  //alert("");
  alert("Your Time is Up");
  clearInterval(intervalID);
 }
 }
</script>
<body  onload="windowOnInitialize()">

<img id="theId" src="small.html" />

我已经尝试了iframe部分上方和下方的脚本,但它在任何一个地方都不起作用。 我很抱歉,如果这是一个重复的问题,或者更确切地说是初级问题,我只是在学习编码。 我一直在网络工作,而不是脚本。

setInterval函数需要一个函数作为第一个参数。 您已经传递了一个字符串"refresh()"。 因此,更改行intervalID = setInterval("refresh()", 6000);以传递函数 - intervalID = setInterval(refresh, 6000);

设置间隔

相关内容

最新更新