duanli9001 2013-04-07 20:59
浏览 33
已采纳

多个页面之间的循环(刷新)?

I have a set of pages with the following names....

  • update1.php
  • update2.php
  • update3.php
  • update4.php
  • update5.php
  • update6.php
  • update7.php

At the moment, I have all 7 open on Chrome and refreshing every 30 minutes using the following code.

<body onload="setInterval('window.location.reload()', 1800000);">

I want to stick all these pages together so that I need only 1 page open. Is there a way to make a page refresh every 5 mins, but load a different section each time?

I was thinking of doing something like this, but it seems a bad way of doing it...

$refresh = $_GET['refresh'];

if (!isset($refresh)) { //update1 stuff; //reload page with &refresh=2 }
elseif ($refresh == 1) { //update1 stuff; //reload page with &refresh=2 }
elseif ($refresh == 2) { //update2 stuff; //reload page with &refresh=3 }    
elseif etc.....

Any ideas?

  • 写回答

2条回答 默认 最新

  • drox90250557 2013-04-07 21:03
    关注

    In your php code that outputs the page html code, try something like this:

    <?php echo ($_GET['refresh'] % 7) + 1; ?>.php // Name of next page
    
    ?refresh=<?php echo ($_GET['refresh'] % 7) + 1; ?>"; // Name of next page + 1
    
    // All together
    <body onload="setTimeout(function() { window.location.href = 'update<?php echo ($_GET['refresh'] % 7) + 1; ?>.php?refresh=<?php echo ($_GET['refresh'] % 7) + 1; ?>';}, 1800000);">
    

    This will open the new page with an incremented number after the specified time interval. The modulo operation helps us run through the pages in a consistent loop.

    References

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?