Skip Navigation

[Resolved] Clicking browser back button reloads the page I'm returning to

This support ticket is created 4 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 1 reply, has 1 voice.

Last updated by davidm-13 4 years, 6 months ago.

Author
Posts
#1681145

Hi, From page A I click a link that redirects me to Page B.
On page B I click the browser back button and want to reload/refresh Page A.
At the moment I have this code in the JS editor of content template for Page A

  window.onbeforeunload = function () {
  window.scrollTo(0, 0);
  }

I understand this code is for repositioning the page top left which actually what I need to do, but this code requires me to also click refresh on Page A, after clicking back button on Page B.
Thanks for any help

#1681179

All you have to do is ask for assistance.
Googling a bit more I found:

// This prevents the page from scrolling down to where it was previously.
if ('scrollRestoration' in history) {
    history.scrollRestoration = 'manual';
}
// This is needed if the user scrolls down during page load and you want to make sure the page is scrolled to the top once it's fully loaded. This has Cross-browser support.
window.scrollTo(0,0);

Works perfectly!
Thanks for your help