首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在url引用脚本中添加5秒等待?

如何在url引用脚本中添加5秒等待?
EN

Stack Overflow用户
提问于 2013-02-02 05:33:54
回答 1查看 1.2K关注 0票数 4

我有url重定向脚本或url引用脚本。

我想增加5秒等待,然后url重定向到所需的url。

代码语言:javascript
复制
 <script>
 var url_index = window.location.href.indexOf('url=');
 if (url_index != -1)
 {
    url_go = window.location.href;
    url_go = url_go.substring(url_index + 4);
    //document.write(url_go);
    window.location.href = url_go;
 }
 var $_ = function(x){if(!document.getElementById){return;} else{ return document.getElementById(x);}}
 </script>  

输出为http://transistortechnology.blogspot.comurl=http://imgur.com

当我打开上面的url然后它突然重定向,但我要加5秒等待。

在上面的脚本代码中是否有可能。

我将该脚本放在blogger头部分。

EN

回答 1

Stack Overflow用户

发布于 2020-05-29 05:36:14

代码语言:javascript
复制
<script>
   var count = 15; // Number of seconds to wait
   var counter; // Handle for the countdown event.

   function start() {
    counter = setInterval(timer, 1000);
   }

   function timer() {
    // Show the number of remaining seconds on the web page.
    var output = document.getElementById("displaySeconds");
    output.innerHTML = count;

    // Decrease the remaining number of seconds by one.
    count--;

    // Check if the counter has reached zero.
    if (count < 0) { // If the counter has reached zero...
     // Stop the counter.
     clearInterval(counter);

     // Start the download.
     window.location.href = "URL to open";
//if you want to open in new window then use window.open(url);
     return;
    }
   }  

   window.addEventListener("load", start, false);
  </script>

  <div>
  Your download will begin in <span id="displaySeconds">15</span> seconds.<br />
</div>

感谢技术专家为这个剧本。我在他的博客上找到了这个

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14658971

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档