将日期中的特定时间重定向到不同的html页面

时间:2015-11-29 22:04:19

标签: javascript html redirect time

我想要一个网页,根据一天中的不同时间重定向到不同的网页。 这是可能的吗,有人可以帮我解决这个问题。 例如, " @ 6am转到第1页" " @上午11点到了第2页" " @ 6pm转到第3页" " @11pm到了第4页"

由于

2 个答案:

答案 0 :(得分:1)

您可以使用.getHours()并根据var date=new Date(); if(date.getHours()==15){//3:00pm window.location="https://www.google.com/webhp?hl=en" }

重定向



var archtype = Raphael('graph', 100, 100);


archtype.customAttributes.arc = function (value) {
            var xloc = 50,
            yloc = 50,
            total = 100,
            R = 30,
            alpha = 180 / total * value,
            a = (180 - alpha) * Math.PI / 180,
            x = xloc + R * Math.cos(a),
            y = yloc - R * Math.sin(a),
            path;
            if (total == value) {
                path = [
                        ["M", xloc, yloc + R],
                        ["A", R, R, 0, +(alpha > 180), 1, x, y]
                        ];
            }else{
                path = [
                        ["M", xloc, yloc - R],
                        ["A", R, R, 0, +(alpha > 180), 1, x, y]
                        ];
            }



return {
            path: path
            };
        };




答案 1 :(得分:0)

那么,你当时不能那么做,但你可以使用setInterval()函数检查某个时间间隔内的当前时间。有点谎言:

var redirectHour = 18;
var redirectMinute = 30;
var interval = setInterval(function() {
      var currentDate = new Date();
      if (currentDate.getHours() == redirectHour &&
          currentDate.getMinutes() == redirectMinute)
           window.location.href = "HtmlPage2.html";
}, 60000);

setInterval()的第一个参数是匿名函数,您可以在其中处理要运行的代码,第二个参数是您希望再次运行函数的间隔(以毫秒为单位)。我把它设置为60 000,这是每分钟。将redirectHour和redirectMinute变量更改为您希望重定向页面的时间。