Tips & Tricks

How to prevent form resubmission when page is refreshed (F5 / CTRL+R)

Reloading a page with F5 in browsers can give some nasty sideeffects - if say last action was deleting…

This little gem in JavaScript prevents that: @@Stackoverflow_icon@@ How to prevent form resubmission when page is refreshed (F5 / CTRL+R)

<script>
  //[How to prevent form resubmission when page is refreshed (F5 / CTRL+R)](https://stackoverflow.com/a/45656609)
  if ( window.history.replaceState ) {
    window.history.replaceState( null, null, window.location.href );
  }
</script>