I can suggest this:
- invoke window.onunload (pay attention to firefox!) and store the current location in the server. important: make this async call.
- in the server save the state of the user (leaving a page)
- write a code in the global request event handler and query this state.
- you can launch threads in the server to invoke the final unload (say, after 5 sec) no new request from the client
I know these steps are hard to implement, but they address your problem and solves it.