Remove event handlers on window and document when the page changes.