How to get previous url including hash fragment using javascript?
As you noted, part of the hash fragment means that you cannot use document.referrer .
If the previous page was on the same origin : you will need to have the code on this page where the full URL will be written, for example, in sessionStorage .
On the previous page, perhaps each time hashChange started:
sessionStorage.setItem("last-url", location);
On a new page, to get the url:
var lastUrl = sessionStorage.getItem("last-url");
If the previous page was in a different source : I'm sure you cannot.
I need the previous URL to be redirected to the previous page.
Actually, you are not doing this. You can simply use history.go(-1) or history.back() , which work regardless of the origin of the previous page.
Tj crowder
source share