Try using onhashchange instead of onpopstate