Stop HTML Form Resubmit on Refresh Page in Javascript

How to prevent PHP HTML form resubmission when page is refreshed/reload (F5/CTRL+R)?
One way to prevent resubmit data is to use the javascript history.replaceState method.



<script>
 if ( window.history.replaceState ) {
    window.history.replaceState( null, null, window.location.href );
}
</script>



Avoid HTML Form Resubmit on Refresh Page using jQuery


<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script>
   $(document).ready(function(){
   window.history.replaceState("","",window.location.href)
   });
</script>