4

I have url redirection script or url refer script.
I want to add 5 second waiting and then url redirect to desired 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>  

Output is http://transistortechnology.blogspot.com?url=http://imgur.com

When I open above url then it redirect suddenly, but I want add 5 second wait.

Is it possible in above script code.

I put that script in blogger header section

Denis Kreshikhin
  • 8,856
  • 9
  • 52
  • 84

2 Answers2

2

See: Javascript - Wait 5 seconds before executing next line
Based on that, the following should probably work:

 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);
     }
 }

Community
  • 1
  • 1
MikeTheTall
  • 3,214
  • 4
  • 31
  • 40
  • Just to be uber-thorough, here's a quick sample that works :) – MikeTheTall Feb 02 '13 at 06:00
-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>

Thanks to technovedant for this script. I found this at his blog

Pranu Pranav
  • 353
  • 3
  • 8