Reload the Page on Hitting Back Button

Reload the page on hitting back button

These headers will force the browser, and proxies if any, not to cache the page and force a new request to the server for that page:

  header("Cache-Control: private, must-revalidate, max-age=0");
header("Pragma: no-cache");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // A date in the past

Chrome 41: Force Reload when pressing the back button

Please check this question that addresses the problem using localStorage/sessionStorage.

How to refresh a page after back button pressed

The Navigator.push method returns a future of the generic type of the Route:

Navigator.of(context)
.push(new MaterialPageRoute<String>(...))
.then((String value) {
print(value);
});

And inside the new route, when you have the value you need:

Navigator.of(context).pop('String');

How to refresh page on back button click?

Try this... not tested. I hope it will work for you.

Make a new php file. You can use the back and forward buttons and the number/timestamp on the page always updates.

<?php
header("Cache-Control: no-store, must-revalidate, max-age=0");
header("Pragma: no-cache");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
echo time();
?>
<a href="http://google.com">Reload the Page on Hitting Back Buttonaaaaa</a>

Or

found another solution

The onload event should be fired when the user hits the back button. Elements not created via JavaScript will retain their values. I suggest keeping a backup of the data used in dynamically created element within an INPUT TYPE="hidden" set to display:none then onload using the value of the input to rebuild the dynamic elements to the way they were.

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


Related Topics



Leave a reply



Submit