Skip to content Skip to sidebar Skip to footer

Browser: Prevent Post Data Resubmit On Refresh Using Only Javascript

I am aware of the many Post/Redirect/Get questions on here. This one is a bit different. I'm unable to find an answer that explains this particular JavaScript solution. When you s

Solution 1:

Answer : WordPress uses window.history.replaceState on every page load.

This prevents the POST from running again on refresh or back button.

Nifty!

Non-WordPress proof of concept here: https://dtbaker.net/files/prevent-post-resubmit.php

Code is:

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

Post a Comment for "Browser: Prevent Post Data Resubmit On Refresh Using Only Javascript"