views:

21

answers:

1

I want to use onbeforeunload to give a message to users before leaving certain pages. Is it possible to know which url they are supposed to jump to at the onbeforeunload event?

Thanks

A: 

Is it possible to know which url they are supposed to jump to at the onbeforeunload event?

No, definitely not. The onbeforeunload event tells you only that the page is about to be unloaded, but not why.

Pekka
It might be possible to add a `click` event listener on every link on the current page. Using that, you could tell at least which outgoing link the user has clicked with some reliability. But it's difficult to implement, and will not work for any other user action (e.g. the user clicking the "back" button).
Pekka
@Pekka: All form.submit events as well to see form submition URLs. And taking into consideration all DOM manipulation (dynamically adding A elements - you have to attach click events to them as well; jQuery `live` may help in this regard).
Robert Koritnik