How to redirect a link to a hash value URL using JS?

Let's say a user goes from greatsite.com/uno#argument to coolsite.com/dos. After some interaction on the second page, I need to send it back to my referrer using Javascript:

window.location = document.referrer; 

The problem with the launch is that document.referrer loses hash values. The user is redirected to the .com / uno website without #argument. The page does not work because its javascript depends on this argument.

+4
source share
3 answers

what about the story?

 if (history.back() === undefined) location.replace(document.referrer); 
+5
source

So link to dos, but add the current hash of the document. So, the dos # argument.

Then connect to the referrer by adding the current hash tag to the referrer.

In other words, carry the hash tag with you through the pages.

0
source

try it

 window.history.go(-1) 

but firefox may ask the user whether to prevent

0
source

Source: https://habr.com/ru/post/1401091/


All Articles