How to reload page if user has returned to browser history

Asked

Viewed 76 times

0

I have a problem, that when the user clicks the back button in the browser menu, it goes to the previous page, but it does not reload and keeps the old content. How can I recharge it when this event happens ?

  • You can try listening by popstate event and check.

2 answers

0


I found the answer to the question. When the "window.performance.navigation.type" object is equal to 2, it means that the user came from a later page by the browser history.

if (window.performance && window.performance.navigation.type == 2) {
    window.location.reload();
}

-1

There is no event that detects whether the user has clicked the back button in the browser history, so I believe the best way is to work with SESSION.

When accessing a page, you fill in a SESSION, if the user visits that page again you check the SESSION, if it has already accessed you can use: location.reload();

I don’t know what language you are using but in C# to call the script in the back-end you can use the following code:
Page.ClientScript.RegisterStartupScript(this.GetType(), "reloadPage", "location.reload();", true);

  • Our guy who’s been sniffing around.

  • Gambiarras move the world, if you can solve this without a show gambiarra, thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.