If you ask about when the page is being refreshed (for example, the user clicks a link or something else), then that doesn't matter, since the page / client side code no longer exists at this point.
So, I would not worry about undoing something in this scenario.
source
share