【问题标题】:How to redirect browser at specific date and time?如何在特定日期和时间重定向浏览器?
【发布时间】:2019-02-23 09:20:29
【问题描述】:

我正在尝试编写一个脚本,允许我在每周五的特定时间重定向到网页。

希望将脚本重定向到实时视频源的 Iframe,一个小时后,让脚本也重定向到 html 文件,该文件将存储在运行启动页面的 PC 上,直到下一个源如下week,它将根据日期和时间再次启动脚本。

过去 3 个小时一直在尝试从我发现的堆栈溢出脚本中挽救一些东西,但没有成功。非常感谢您对此的帮助!

【问题讨论】:

  • 我不清楚用户进程到底是什么。带我浏览一下:我导航到一个网页,其中的闪屏给了我一些日期时间,重定向将发生。在那个确切的时间,如果我在页面上,重定向会将我带到另一个网页?还是在该页面内创建 iframe?

标签: javascript html redirect iframe browser


【解决方案1】:

我希望这对你有用。

function myFunction() {
   var d = new Date();
   var n = d.getDay()
   var time=.getHours()
   if(n==5)
   {
   //based on time
   if(time==14)
   {
    window.location.href="www.YourRedirectpage.com";
   }

 }

【讨论】:

    【解决方案2】:

    这应该可以工作(ES5 语法):

    Date.prototype.hour = function () {return (this.getHours())}
    Date.prototype.day = function () {return (this.getDay())}
    var today = new Date()
    
    if (today.hour() == "10" && today.day() == "6") {
      // change you url here, such as; location.href ="friday url";
    }
    else {
      // keep (or re-attribute) your base url, such as; location.href ="base url";
    }
    

    【讨论】:

      【解决方案3】:

      我猜你想在 UI 中进行某种简化的工作,它会持续观察并为你重定向,而你不需要手动干预太多。您应该使用 Javascript 中的 setTimeout 来实现这一点。

      此解决方案的作用是计算即将到来的星期五与特定时间到当前日期时间之间的毫秒差,并启动超时事件。

      希望这很容易理解并对您有所帮助。

      GIT 仓库:https://github.com/helloritesh000/how-to-redirect-browser-at-specific-date-and-time

      <!DOCTYPE html>
      <html>
      <body onload="RedirectTo(5, 15, 49, 30);"> <!-- RedirectTo(day(1-7(Monday)-(Sunday)),1-24 hour,1-60 min,1-60 sec) -->
      
      <h1>This will reload redirect page</h1>
      @ - <p id="demo"></p>
      
      <script>
      function getNextDayOfWeek(date, dayOfWeek) {
          // Code to check that date and dayOfWeek are valid left as an exercise ;)
      
          var resultDate = new Date(date.getTime());
      
          resultDate.setDate(date.getDate() + (7 + dayOfWeek - date.getDay()) % 7);
      
          return resultDate;
      }
      
      function RedirectTo(day, hour, min, sec) {
        var d = new Date(getNextDayOfWeek(new Date(), day));
        d.setHours(hour);
        d.setMinutes(min);
        d.setSeconds(sec);
        document.getElementById("demo").innerHTML = d;
        var totalMilliSecDiff = d-new Date();
        if(totalMilliSecDiff > 0)
        {
          setTimeout(function(){ window.location.href = "http://www.google.com"; }, totalMilliSecDiff);
        }
      }
      </script>
      
      </body>
      </html>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-05
        • 2016-10-18
        • 2013-07-24
        • 1970-01-01
        • 2013-05-27
        • 1970-01-01
        相关资源
        最近更新 更多