Logging in, redirecting and history.go()
===

I'm writing a js script that redirects the user after logging in.

The login form is located on a page: /login.

I'd like to redirect the user to the location that he was on when he pressed the login button. (The login button is available on every page in the header.)

I could do window.history.go(-1) when the user completes the login procedure, but when users enter the site at sitename.com/login and login, they will be redirected to whatever site they were on before they went to the site.

Is there a way of detecting if the user was on the site before he tried to log in, and do something different if they were?

