Hi,
I am not sure if we can achieve this when clicking another menu button, but You can implement Custom JavaScript when to achieve the warning when closing a browser tab.
I think the Exit Intent module on the Mendix Marketplace does what you need.
https://marketplace.mendix.com/link/component/21721
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.