open the popup when user clicks on an external link

Hello,

I am wondering if there is a way to open the popup when a visitor clicks on a link which will lead him to an external page.
similarly I'd like to trigger the popup also when closing the page.

thank you in andvance!
Andrea