How to pause the execution for a time (similar to a "Wait" or "Sleep")?

Asked

Viewed 5,083 times

4

This code is working and running on an existing account on this website, what I want to do is: Add a pause, a kind of While, Wait, Sleep or ReadyState, after login and before going to the new tab. This line would replace the window.close().

<html>
    <head>
      <title>L2 CR AUTO LOGIN</title>
    </head>
    <body>
      <form id="loginForm" name="loginForm" method="post"    action="http://zionweb.l2cr.com/gamecpc6/index.php">
        <select name="uni_url" id="logServer" class="validate[required]">
          <option  class=""  value="http://zionweb.l2cr.com/gamecpc6/index.php" fbUrl=""  cookieName=""  >
             Personagem1
          </option>
        </select>
        <input id="username" name="username" type="text" value="CHECKBOSS" class="" />
        <input id="password" name="password" type="password" value="123456" class="" />
        <input type="hidden" id="loginKid" name="kid" value=""/>
        <button onclick="myFunction()">Enter</button>
      </form>

      <script> function myFunction() {
         document.loginForm.submit(); 
         window.close();
         window.open("http://zionweb.l2cr.com/gamecpc6/classes/view_templates/rbs.php");    
      } </script>
    </body>
</html>
  • 2

    Wait, Sleep for what ? What is your intention what you want to accomplish, try to leave your question more objective to have objective answers too, for more and it is there Eirc / o

  • I need a Wait before window.open(); to open the tab so that the account has already been logged in. Otherwise the automatic login will not happen, because when the page is logged in right after I open a new tab with the URL I want. Without Wait the page will result in not found.

1 answer

3

As it was not specified if Voce logs the account for an ajax or an api I will leave a simple solution, but not the most advisable, Voce can use setTimeout to determine a time to run a function x, but I believe the most advisable in this case is to analyze which is the possible callback of ajax/api to be able to perform another action.

setTimeout(alerta, 3000); // segundo parámetro e o timing para executar a função 



function alerta() {
  alert("LOL");
}

  • 1

    Highlander in case it wouldn’t be better a setTimeout?

  • 1

    @Samirbraga Exactly, the setTimeout would be more suitable than the interval, because it would run only once from certain time, thanks for the tip there, I had forgotten!

  • That’s right. I thought I’d let you know. :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.