Hello!

I need to make a timer that moves the user to another page when time passes. Example.

Fight one user with another. One uses one attack, the other uses another. But after a while one of them realized that if he continued the battle, he would lose. Fight time 5 minutes. So that user waits for these 5 minutes, throws them out of the battle and did not add anyone, did not take away his glasses. I need to create a timer, which after the expiration of the time, will throw out the user who cheated on the page of loss, and who was waiting for the enemy to be like - on the page of winning.

Is it possible to make this timer so?

<head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251" /> <title>тест</title> </head> <body> <div id="timer"></div> <script> var limit = 5; // в секундах function processTimer() { if (limit > 0) { setTimeout("processTimer()", 1000); limit--; } else { // здесь действия после завершения таймера //.. } var limit_div = parseInt(limit / 60); // минуты var limit_mod = limit - limit_div * 60; // секунды // строка с оставшимся временем limit_str = "&nbsp;&nbsp;"; if (limit_div < 10) limit_str = limit_str + "0"; limit_str = limit_str + limit_div + ":"; if (limit_mod < 10) limit_str = limit_str + "0"; limit_str = limit_str + limit_mod + "&nbsp;&nbsp;"; // вывод времени el_timer = document.getElementById("timer"); if (el_timer) el_timer.innerHTML = limit_str; } processTimer(); </script> </body> 

How to re-address the pages?

    3 answers 3

    You noticed that setTimeout is inside the processTimer function, and the processTimer function processTimer not be called using only processTimer(); on the last line of the script?

    Therefore setTimeout needs to be taken out of the processTimer function and rejoice!

       location.href=URL; 
      • thanks, I'll try now! although similar tried! - RollerZ
      • does not work! - RollerZ
      • what does he say? - Yoharny Babay
      • shows nothing! time is running out! Try you and throw off the source code, I'll see! - RollerZ
      • Pff .... no one will work for you here, we help, and we don’t do work for someone, this is not a freelancer for you - Mikhail Nikolaev

      <meta http-equiv = "refresh" content = "2000; url = http: //example.com/">;

      content = "time (in seconds); url = link"