【问题标题】:When redirecting to another webpage the function keeps repeating重定向到另一个网页时,该功能会不断重复
【发布时间】:2019-09-09 19:36:12
【问题描述】:

我想要做的是运行一个动画 7 秒然后重定向到实际的 index.html 文件,但是当我使用下面的代码时,动画在 7 秒内完成它重定向到 index.html 然后它不断重新加载索引.html。我正在考虑使用 for 循环或 if 语句,但我真的不知道从哪里开始。

$(function() {
   setTimeout(function() {
      $(".fly-in-text").removeClass("hidden");
   });
   setTimeout(function() {
      $(".allblack").remove();
   }, 7000);

  $(document).ready(function() {
     // Handler for .ready() called.
     window.setTimeout(function() {
        location.href = "index.html";
     }, 7000);
  });
});

What my code currently looks like

【问题讨论】:

  • 不要发布代码图片。更多信息请查看meta.stackoverflow.com/q/285551
  • 我建议检查location.href 不是index.html,然后才加载索引。否则你已经在 index.html 中,不需要重新加载
  • 我已经为它尝试了一个 if 语句,然后它会每 1 秒刷新一次页面。

标签: javascript function if-statement event-handling dom-events


【解决方案1】:

我必须在要重定向到的页面上放置一个元标记

<meta http-equiv="refresh" content="5;url=index.html" />

然后我必须添加一个 JavaScript 函数脚本

function leave() {
    window.location = "index.html";
  }
  setTimeout("leave()", 5000);

【讨论】:

    猜你喜欢
    • 2017-07-14
    • 2015-12-07
    • 1970-01-01
    • 1970-01-01
    • 2021-05-10
    • 2017-08-03
    • 2021-10-28
    • 1970-01-01
    • 2012-01-03
    相关资源
    最近更新 更多