Use the hashchange event.