I am opening a popup window and attaching an onbeforeunload event to it like this:
win = window.open(\"http://www.google.com\", \"\", \"width=300px,height=30
Unfortunately, you're trying to communicate across domains which is prohibited by JavaScript's same origin policy. You'd have to use a server-side proxy or some other ugly hack to get around it.
You could try creating a page on your site that loads the external website in an iframe. You could then pop open that page and listen for it to unload.