You normally insert some JavaScript into the head of your sites html code. Try looking at hotscripts or searching on Google for something like "free exit popup script" without the quotes.
Read up on the "onUnload" event for the BODY tag of your page. You can use it to run a javascript function as the user exits the page.