My problem is a bit more complex than using the following simple JavaScript code
window.onbeforeunload = function (e) {
return 'Are You Sure?';
};
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
- closing the browser tab/window
- navigating to another domain
The JavaScript method above does not solve my problem because it is evoked even when the user navigates within the domain.
Short:
- User tries to close window -> Show dialog
- User changes www.mydomain.com/shoppingcart url to www.google.com in the browser's address bar -> Show dialog
- User navigates to www.mydomain.com/checkout with the checkout button or presses the back button in the browser -> Do NOT show the dialog