JavaScript back button issue doesn't like it when customers use the back button to make corrections after submitting a failed transaction.

You can prevent this by leveraging sessionStorage to track errors and reloading the page if the back button is pressed.

This example is specific to WooCommerce, but can be altered to suit any cart.
if (typeof Storage !== 'undefined') {
	if (location.href.indexOf('/store/checkout/pay/') !== -1 && location.href.indexOf('wc_error') !== -1) {

		window.sessionStorage.setItem('wooError', '1');
	else if (location.href.indexOf('/store/checkout/pay/') !== -1 && location.href.indexOf('wc_error') === -1 && window.sessionStorage.getItem('wooError')) {
		// prevent back button to go back and correct credit card after error,  try to take them back to initial checkout page
Posted by
Snippet Viewed 1528 times.

Share your JavaScript code snippets:

  • Get some recognition & link back to your site.


Submit | Browse

Most Recent javascript snippets

Most Viewed