I'm not sure you can accomplish everything you want to do, but you should check out the JavaScript 'onUnload' event handler. It is placed in the body tag and is intended to run a JavaScript routine when someone tries to leave a page. I've seen it used for pop-ups.
Obviously, it will only work when a user has JavaScript enabled.
Hope that helps.
Reputation Points: 15
Solved Threads: 5
Junior Poster in Training
Offline 87 posts
since Aug 2005