One way to do this would be to have that initial button instead open a popup page with your desired message (e.g. “You will now be redirected to a page outside this application.”) and then have that popup have a confirmation button (e.g. “Okay”) and have that button instead open the outside link.
Same as pgadmin does when you have a query-tab open with a query you modified:
There is a widget for that: https://appstore.home.mendix.com/link/app/78474/Bizzomate/Bizzomate-LeaveAction , like Ronald says in his answer to this question.
What do you want to achieve? Or what is your problem description?
Personally, getting a popup while leaving a website is really frustrating, not user friendly and does not help to keep the user on page.