title: Prevent user from accidentally navigating away
body: <p>My problem is a bit more complex than using the following simple JavaScript code</p>
  
  <pre><code>window.onbeforeunload = function (e) {      
    return 'Are You Sure?';
  };
  </code></pre>
  
  <p>On an e-commerce web page I would like to remind the user that he has items in the shopping cart so that he can change his mind before</p>
  
  <ol>
  <li>closing the browser tab/window</li>
  <li>navigating to another domain</li>
  </ol>
  
  <p>The JavaScript method above does not solve my problem because it is evoked even when the user navigates within the domain.</p>
  
  <p>Short:</p>
  
  <ol>
  <li>User tries to close window -> Show dialog</li>
  <li>User changes www.mydomain.com/shoppingcart url to www.google.com in the browser's address bar -> Show dialog</li>
  <li>User navigates to www.mydomain.com/checkout with the checkout button or presses the back button in the browser -> Do NOT show the dialog</li>
  </ol>