I think the Exit Intent module on the Mendix Marketplace does what you need.
I hope this helps.
In page properties for the close button, you can select microflow (where you show the warning message) action and write the custom logic. This is when user clicks close button of the page. If the user clicks menu then for each menu navigation call one common microflow and write the logic to show warning message and then navigate to the respective page.