• During processing of a shortcode, my plugin reacts to a URI query string

    ?action=1

    , changes some state in the database, and includes a status message in the content returned by the shortcode.

    When the page is eventually rendered, the browser’s Location bar still contains that query string, as part of the URI.

    If the user then refreshes the page, my shortcode processing will again process the query string but now see that the state has already been changed, so include a warning message in the content by the shortcode.

    The warning is confusing to the user, so I’m looking for a way to remove that query string, after it has first been processed.

    I considered including some javascript which would remove the query string from the URI and reload the page. But the user would then never see the status message included when the query string was originally processed.

    Any ideas on removing the query string after it’s been processed?

    • This topic was modified 3 years, 9 months ago by flymike.
Viewing 6 replies - 1 through 6 (of 6 total)
  • A little bit of googling and I found

    if (history.pushState) {
        var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname;
        window.history.pushState({path:newurl},'',newurl);
    }

    Untested

    And

    history.replaceState(null, "", location.href.split("?")[0]);

    Untested

    Thread Starter flymike

    (@flymike)

    Thanks. I realize I can reload the page without the query string using JS but, if I do that, the user will never get chance to see the status message which I present on the original page.

    To clarify, I present a status message when the state is changed, but a warning message if the user subsequently attempts to change the state again.

    Maybe one solutions is a 5 second delay before the JS reloads the page, so that the user can briefly see the status message. But that seems a bit of a hack…

    Both solutions remove the query string without reloading the page, apparently.

    Thread Starter flymike

    (@flymike)

    My apologies. I missed that point completely. I’ll research that.

    Thanks again.

    That is OK, the search term I used was

    modify query string without reloading page

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Change URI query string while processing shortcode’ is closed to new replies.