Thursday, 18 February 2021

How to know when a page redirect or refresh action is cancelled, Javascript

I am currently working on a page where a preloader is shown to the user onPageNavigating, and when the user cancels the navigation from the browser, I would like to remove the preloader.

What i have tried.

  • Create a countDown timer
  • Start timer onPageNavigating
  • If timer elapse, assume navigation was cancelled
  • Hide preloader

But the problem with this method is that the time of navigation may vary based on network speed which makes it not feasible for my use-case.

What are other options to implement or is there an available browser API for this? because I can't find anything related via search.

EDIT:

Similar use-case where issue persists: For example visit: https://developer.android.com/guide or any link within its domain and notice the horizontal preloader at the top of the page. When you start navigation or refresh from the page you see the preloader shown but the challenge persist as I explained. Cancel the refresh immediately and the preloader would still be visible which isn't meant to be so.



from How to know when a page redirect or refresh action is cancelled, Javascript

No comments:

Post a Comment