How to Refresh Page on Back Button Click

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">How to Refresh Page on Back Button Clickaaaaa</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();}
}

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');

Refresh page on back browser button

Although your questions is very poorly written, I believe it is more important that you get the answer you're looking for.

Do the following:

  1. Add event listener to the window/document(in your case, keydown)
  2. Get the ascii code of backspace(0x08 or 8 in decimal)
  3. Prevent the default functionality of keydown
  4. Refresh the page if it is backspace

Here it is in code.

window.addEventListener('keydown', function(e)
{
if( e.keyCode == '8' )
{
e.preventDefault(); // prevent backspace from going to browser
// history
// add reload code
location.reload();
}
}, false);

Link to event listener

MDN Event Listeners

Chrome 41: Force Reload when pressing the back button

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



Related Topics



Leave a reply



Submit