根据时间做跳转
我有A。B2个页面,如何根据客户端的时间来跳转
比如7点到18点是a页面
其余时间是b页面
------解决方案-------------------- <script>
function test(obj) {
var hour = (new Date).getHours();
if (hour> =7 && hour <18)
obj.href= "a.html ";
else
obj.href= "b.html ";
}
</script>
<a href= "# " onclick= "test(this) "> test </a>
------解决方案--------------------在页面上判断当前时间范围:
<script>
var nh = new Date().getHours();
switch(nh){
case 1:window.location= "http://www.sina.com.cn ";break;
case 2:window.location= "http://www.sohu.com ";break;
case 3:window.location= "http://www.163.com ";break;
case 4:window.location= "http://www.csdn.net ";break;
//case 其他的小时;
default:window.location= "http://www.jxxg.com ";break;
}
</script>
------解决方案--------------------JF
<script type= "text/javascript ">
<!--
function automaticRedirectByTime(){
var currentTime = new Date();
var numHour = currentTime.getHours();
var strTargetPage = "b.html ";
if (numHour> =7 && numHour <18)
{
strTargetPage = "a.html ";
}
if (document.location.href.indexOf(strTargetPage) == -1)
{
document.location.href = strTargetPage;
}
}
//-->
</script>
</head>
<body onload= "automaticRedirectByTime(); ">
</body>