4

我有 url 重定向脚本或 url 引用脚本。
我想添加 5 秒等待,然后 url 重定向到所需的 url。

 <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.com网址= http://imgur.com

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

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

我把那个脚本放在博客标题部分

4

2 回答 2

2

请参阅:Javascript - 在执行下一行之前等待 5 秒
基于此,以下内容可能会起作用:

 url_go = ""
 function doRefer() {
     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);
        setTimeout(function () {window.location.href = url_go;}, 5000);
     }
 }

于 2013-02-02T05:39:12.873 回答
-1
<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>

感谢 technovedant 提供这个脚本。我在他的博客上找到了这个

于 2020-05-29T05:36:14.033 回答