script: fix issues with onpopstate