4

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

window.location = document.referrer;

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

3 Answers 3

5

what about using the history ?

if (history.back() === undefined) location.replace(document.referrer);
Sign up to request clarification or add additional context in comments.

4 Comments

This works ... even in IE6! Wow! My mind is blown! The laws of physics have been broken!
Just be sure to provide a fallback behavior in case there are no pages in the history. For example, if your page was opened in a new tab.
That's strange when opening in new tab the document.referrer contains the hash, whereas if it's in the same window the hash isn't here
I used history.length > 1 instead
0

So link to dos, but append the current documents hash tag.. So dos#argument..

Then link to the referrer by appending the current hash tag to the referrer.

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

2 Comments

Uno does not pass the hash to Dos because it could be written by another person.
Then use JavaScript, any time you change the hash, loop through all the links and change the JS on the hrefs to include the hash.
0

try this

window.history.go(-1)

but firefox may ask user whether to prevent

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.