jQuery页面计时器 [英] Jquery Page Timer

查看:79
本文介绍了jQuery页面计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jQuery/PHP可以吗?我想让我的网页在一天的特定时间自动转到另一个网页.例如,我有一个早餐"页面,该页面应该在中午自动重定向到午餐"(www.mylunchpage.com)页面.然后,午餐页面在下午5点进入晚餐"(www.mydinnerpage.com)页面.我希望所有这些都是基于一天中的时间,而不是基于计时器.

Is this possible using jQuery/PHP? I am looking to have my webpage automatically go to a different web page at a certain time of day. For example, i have a 'breakfast' page that is supposed to auto-redirect to the 'Lunch' (www.mylunchpage.com) page at noon. Then the lunch page go to 'Dinner' (www.mydinnerpage.com) page at 5pm. I want it all based on time of day on not on a timer.

是的,浏览器将全天开放...

Yes, the browser will be open all day...

关于如何进行这项工作的任何想法?任何建议将不胜感激.

Any idea on how to make this work? Any advise will be greatly appreciated.

推荐答案

可以使用Javascript函数setInterval()定期检查(每分钟,每5分钟等)时间.如果当前时间达到了您的目标之一,则可以重定向.

The Javascript function setInterval() can be used to check at certain intervals (every minute, every 5 minutes, etc.) to see what time it is. If the current time hits one of your targets, you redirect.

类似的东西:

function checkTime()
{
  var date = new Date();
  var hour = date.getHours();
  var min = date.getMinutes();

  if (hour == 12 && min == 0)
    window.location = 'noon.html';
  else if (hour == 17 && min == 0)
    window.location == '5pm.html';
}

$(document).ready(function(){
  setInterval(checkTime, 60000); // This will run checkTime every minute
});

这篇关于jQuery页面计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆