Replace 'beforeunload' with 'pagehide' in the browsing history