• 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.

    1. This is applying to all pages in the website, not just registration pages.
    2. 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?

    • This topic was modified 1 year, 10 months ago by sanumolu5.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter sanumolu5

    (@sanumolu5)

    Is what I did the optimum solution? Can’t we do anything to make it to pitch perfection from user experience point of view?

Viewing 1 replies (of 1 total)
  • The topic ‘reload on browser back button, only for few pages’ is closed to new replies.