Forum Moderators: open
The document object has a referrer property. So all you need to do is read that property and redirect the visitor, with
location = "[the other URL]"
The problem with that property is that it is very unreliable: browser settings and firewalls may alter or remove it.