automatically reload a page by clicking on back in the browser [closed]

1

Hello, good morning, I want to know if there is a way to make a page automatically reload because I have problems when giving the button back in the browser does not generate new codes, and I must update the page to make it happen

    
asked by JHOSEP LUIS LOOR ANDRADE 11.10.2016 в 15:14
source

4 answers

1

Add this header to your PHP to make sure it does not return a cached page:

<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>
    
answered by 13.10.2016 / 09:34
source
1

The ideal if you use PHP is that when you process the form in php (collect variables and put them in a database for example) make an address with a header.

Example:

<?php //ejemplo

$datos = $_REQUEST['datos'];
$sql = "INSERT tabla SET datos = '" . $datos . "'";
$res = mysql_query($sql);
header("Location:" . $_SERVER['HTTP_REFERER']); //la pagina anterior o poner la pagina que tu quieras
die();

?>
    
answered by 13.10.2016 в 09:32
0

Before I think I've misunderstood the question. If you want to go back to the previous page as the back button of the browser acts, then you should use the history object. You can use the following function:

window.history.back()

You can find the documentation (in Spanish) about this element here .

    
answered by 11.10.2016 в 16:07
0

Thank you so much for your help I really wanted to do it and it worked for me if there is another way to interpret it, it would be worth to help me but I wanted to do it

<input type="hidden" id="refreshed" value="no">
  <script type="text/javascript">
      onload = function () {
         var e = document.getElementById("refreshed");
         if (e.value == "no")
             e.value = "yes";
         else {
             e.value = "no";
             location.reload();
         }
     }</script>
    
answered by 13.10.2016 в 12:13