detecting browser close all conditions
<p>This question has been asked many times before but none of the previous ones hit all the issues.  I have a shopping cart that I store in session state.  I'd like to detect when the user leaves the site so I can ask if they'd like to save their cart.  I'd prefer not to automatically store the cart, I hate sites that I re-visit and there's all this leftover stuff in the cart that I'm no longer interested in.</p>

<p>I've tried onbeforeunload but it fires when the user hits the back/previous buttons.  Is there any way from within onbeforeunload I can determine the url where the browser will be going next?  Then I can check if it is local and ignore it, otherwise if leaving the site for good a prompt can be displayed.</p>

<p>Maybe I am not getting something?  How do you handle this situation?</p>
