How can i write JS function to catch up Reload Button (on browser) then i pressed on.

etc. -> and back button too.

Thank you.


function hardReload(fromServer) {
  // Perform a hard reload of the document.
  // This kind of reload resets form elements to their default values
  // Call with hardReload(false) to retreive from browser cache (if available)
  // Call with hardReload(true) to force the page to be re-served by the server
  fromServer = (!fromServer) ? false : true;

function softReload() {
  // Perform a soft reload of the document.
  // This kind of reload does not reset form values 
  // and is useful when a user has entered data into a form and you don't want to erase it.
  // Unfortunately, some browsers (notably some versions if IE) will perform a hard reload.

history.go(0) is probably not used as much as history.go(-1) , which (when it works) soft-reloads the previous page, emulating the browser's back button.

Above, I wrapped the statements up as functions for illustration. You can use location.reload(true) , location.reload(false) and history.go([I]N[/I]) anywhere in your code as appropriate.