Nope, you can't tell the difference between an onUnLoad called by Refresh, closing the browser, typing in a new address, clicking a link in the same domain and so on...
You could try using a frameset -- you can have a frameset consisting of only one frame -- and using an onunload handler in the frameset. All your offsite links would then need target="_top" and this should, theoretically, work. There are other sneaky techniques, such as a small popup moved offscreen that periodically checks the closed property of the window in question.
However, it's a pretty damned annoying thing to do. It's what porn sites do to try to prevent you from leaving, and absolutely nobody likes it. (Not that I habitually surf porn sites, you understand...)
I reckon every popup loses you a sale. A popup on exiting might not lose you the sale, but it will almost certainly lose you any repeat business.
Whilst Rewboss's frameset solution is a good one, you should note that it still doesn't fix the problems with a user refresh or typing in a URL on your domain. You have the added problem of squeezing users into the frameset even if they come through an SERP (Search Engine Results Page*). As you're probably beginning to see now, it's just not worth the trouble.
*Is that right? I've always just thought it stood for that...