reload on browser back button, only for few pages
-
Hi,
I have registration forms of various types. After registration is complete, when the user goes back using browser back button, it has filled in forms as it is taking from history. So, I would like to clear the registration forms when browser back button is clicked.
I created back-button-reload.js with the following code:
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(); } });
and have included this in themes/functions.php
function enqueue_back_button_reload_script() { wp_enqueue_script( 'back-button-reload', get_stylesheet_directory_uri() . '/back-button-reload.js', array( 'jquery' ), '1.0', false ); } add_action( 'wp_enqueue_scripts', 'enqueue_back_button_reload_script' );
However, I feel two minor issues with this.
- This is applying to all pages in the website, not just registration pages.
- When browser back button is clicked, it is showing the page first while still reloading, and hence it is taking few seconds for reload to complete, during that brief time, I see filled in form.
What and how can I do to address these two issues?
The page I need help with: [log in to see the link]
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘reload on browser back button, only for few pages’ is closed to new replies.