我有一个活动/俱乐部网站,其网页mon.html到sun.html。当您在星期二访问该网站时,mon.html页面会重定向到missed_mon.html,依此类推至sun.html。但是,如果您在凌晨5点之前的星期二访问该网站时点击了mon.html页面,则不会重定向,您可以查看该网站。如果您在周三凌晨5点之前访问该网站,情况也一样。我试图让mon.html页面在周三不显示,无论是在凌晨5点,还是在周二凌晨5点之前仍然可见。该规则也适用于所有其他页面,即如果它在星期四,Mon / Tue.html无法查看,但wed.html可在星期四上午5点之前查看。我希望这是有道理的。我星期一到目前为止的代码是......
var d = new Date();
var s = d.getDay();
var r = d.getHours();
if ((s>1 || s==0) && (r>5)){
window.location = "http://dundaah.com/docs/missed_mon.html";
}

sun.html页面不需要任何代码,周二也是..
var d = new Date();
var s = d.getDay();
var r = d.getHours();
if ((s>2 || s==0) && (r>5)){
window.location = "http://dundaah.com/docs/missed_tue.html";
}

等。提前致谢。将其更改为PHP解决方案
答案 0 :(得分:0)
将以下代码保存为服务器中的index.php并浏览到它,它将检查服务器时间并转发到所需页面。决定链接的逻辑必须自己完成。
<?php
$timeinhour = date("H"); // get time in 24-hour format
$dayis = date("D"); //Get day in string format - eg: Mon Sun etc
//Compare your logic as required
// time between Sun 5:00 AM to Monday 4:59AM
if (($dayis = "Sun" && $timeinhour > 4 ) or ($dayis = "Mon" && $timeinhour <5))
{
header( 'Location: link1.html'); //forward to the desired link
}
else if (($dayis = "Mon" && $timeinhour > 4 ) or ($dayis = "Tue" && $timeinhour <5))
{
header( 'Location: link2.html');
}
?>
为您需要的所有日间逻辑执行此操作。
答案 1 :(得分:0)
确实,有很多场景,但我建议您使用下面的解决方案,因为我看到您寻找JavaScript解决方案。
以下脚本位于您的主页或索引页面,注意:在body标记内。
我认为您应该根据要显示的时间显示指向您网页的链接。
<script>
var date = new Date();
var allweek = new Array(7);
allweek[0]= "missed_sun.html";
allweek[1] = "missed_mon.html";
allweek[2] = "missed_tue.html";
allweek[3] = "missed_wen.html";
allweek[4] = "missed_thu.html";
allweek[5] = "missed_fri.html";
allweek[6] = "missed_sat.html";
var hour = date.getHours();
var today = date.getDay();
var one ="1";
var add = parseInt(today,10)- parseInt(one,10);
var target = allweek[add];
var page = allweek[today];
if (hour >= 0 && hour < 17){ // here you check if only file for today should be linked and shown or yesterday file as well
var todaylink = document.createElement('a');
var todaylinktxt = document.createTextNode("today");
todaylink .appendChild(todaylinktxt);
todaylink .href = page;
document.body.appendChild(todaylink );
var br = document.createElement('br');
document.body.appendChild(br);
var yesterdaylink = document.createElement('a');
var yesterdaytxt = document.createTextNode("yesterday");
yesterdaylink.appendChild(yesterdaytxt);
yesterdaylink.href = target;
document.body.appendChild(yesterdaylink);
}
else if(hour >= 17) // here you confirm that only file for today should be linked and shown
{
var todaylink = document.createElement('a');
var todaylinktxt = document.createTextNode("today");
todaylink .appendChild(todaylinktxt);
todaylink .href = page;
document.body.appendChild(todaylink );
}else{}
</script>
然后在每个页面放置以下脚本,**注意:在body标签内**
<script>
var date = new Date();
var allweek = new Array(7);
allweek[0]= "missed_sun.html";
allweek[1] = "missed_mon.html";
allweek[2] = "missed_tue.html";
allweek[3] = "missed_wen.html";
allweek[4] = "missed_thu.html";
allweek[5] = "missed_fri.html";
allweek[6] = "missed_sat.html";
var hour = date.getHours();
var thisfile =location.pathname.substring(location.pathname.lastIndexOf("/") + 1);// make sure this get the exact file name like like in url ,otherwise put the name of current file as in url
var today = date.getDay();
var one ="1";
var yesterday = parseInt(today,10)- parseInt(one,10);
var filefortoday = allweek[today];
var fileyesterday = allweek[yesterday ];
if (thisfile == filefortoday ){ // it means that is a day for current file , so nothing will happen
}else if(thisfile == fileyesterday ){ // check if your current file day suppose to be yesterday
if (hour < 17){ }else{ window.location = "http://dundaah.com/docs/"+filefortoday;} // check whether it's time finished or not
}else{
window.location = "http://dundaah.com/docs/"+filefortoday;
}
</script>
对我来说很好,希望能帮助你
答案 2 :(得分:0)
通过js
解决了这个问题
var d = new Date();
var s = d.getDay();
var r = d.getHours();
if ((s>1 || s==0) && (r>5 || s==3 || s==4 || s==5 || s==6 || s==0)){
window.location = "http://dundaah.com/docs/missed_mon.html";
}
这是针对mon.html的,其余的我根据当天删除“|| s == 3或|| s == 4”