Skip to content

Instantly share code, notes, and snippets.

@nilshendriks
Created June 16, 2022 10:33
Show Gist options
  • Save nilshendriks/3a0db9cbb01ea9f8e707b0d45fb0edf1 to your computer and use it in GitHub Desktop.
Save nilshendriks/3a0db9cbb01ea9f8e707b0d45fb0edf1 to your computer and use it in GitHub Desktop.
legacy script for reloading page when user browsed back with back bjtton
// this script checks if browser go back button was used to get to this page and if so reloads the page to update cart number
// deprecated
// check PerformanceNavigationTiming.type to update this soon. initial test returns nothing... and different between chrome and firefox.
// http://wpt.live/navigation-timing/nav2_test_navigation_type_backforward.html
window.addEventListener( "pageshow", function ( event ) {
var historyTraversal = event.persisted || ( typeof window.performance != "undefined" && window.performance.navigation.type === 2 );
if ( historyTraversal ) {
// Handle page restore.
window.location.reload();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment