How to automatically redirect or rewind to the previous page?

Asked

Viewed 206 times

0

I have this php and js code on the login page, it redirects to another page after 4 seconds, but I wanted it to redirect to the previous or source page that had sent the user to this login page. How to do it, because I’ve tried it many times and I can’t do it.

Follow the code below:

      $clubeSorte->mensagemSucesso("Login feito com sucesso! Será redirecionado brevemente. Se não for redirecionado clique <a href='".URL_PESQUISA."'>aqui</a>");

      ?>

     <script>$(document).ready(function(){
        function redirect(){
          window.location = "<?php echo URL_PESQUISA; ?>";
        }
        setTimeout(redirect, 4000);
      });</script>
  • Maybe window.history.go(-1); in javascript help you.

  • Ok worked but I had to put window.history.go(-2); ... By the way I had already tested this but it must have been wrong or wrong. Thank you very much.

1 answer

0


Solved, can maintain all functions and just replace the part of js window.Location = ""; by window.history.go(-1);

That’s the whole code: $clubeSorte->messageSupport("Login successfully done! It will be redirected soon. If it is not redirected click here");

  ?>

 <script>$(document).ready(function(){
        function redirect(){
          window.history.go(-2);
        }
        setTimeout(redirect, 4000);
      });</script>

Browser other questions tagged

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