If you can get the instance of the popup, then you can use popup.exit :)
Upto my knowledge there is no method like onunload. But I saw somebody selling similar code at codeclerks. I don't know how...