用JS实现一个定时间段的跳转
用JS实现一个定时间段的跳转
常见的定时跳转就是说指某个时间比如30分钟或30秒进行页面跳转
但实现我们工作常见的就是某个活动往往是周末或节假日才开始,这时不可能有人守着帮你跳转页面(而且涉及的页面会很多,活动一般会多个页面宣传)
但实现我们工作常见的就是某个活动往往是周末或节假日才开始,这时不可能有人守着帮你跳转页面(而且涉及的页面会很多,活动一般会多个页面宣传)
JS实例:
<script languge="javascript">
<script languge="javascript">
//取得指定日期及时间的毫秒数
datetime = new Date(2006, 3, 25, 0, 0, 0);
datetime = datetime.getTime();
datetime = new Date(2006, 3, 25, 0, 0, 0);
datetime = datetime.getTime();
//取现在日期及时间的毫秒数
thentime = new Date();
thentime = thentime.getTime();
thentime = thentime.getTime();
//取他们之间的毫秒差
difftime = datetime-thentime;
url = "http://youname.com/xxx.html";
url = "http://youname.com/xxx.html";
//如果小于0则直接跳转
if (difftime<=0)
{
document.location.href = url;
}else
{
window.setTimeout("document.location.href='"+url+"'", difftime);
}
</script>
if (difftime<=0)
{
document.location.href = url;
}else
{
window.setTimeout("document.location.href='"+url+"'", difftime);
}
</script>