Playing with any unload scripts will typically leave you disappointed. Browsers all like to handle these sorts of things differently and there are a ton of restrictions.
But if you insist on using the events then I'd suggest taking a look at the pageHide event for Firefox and Chrome. You'll want to add a check to make sure the event is supported, and then probably use the addEventListener (and attachEvent for IE8 and lower) to actually assign the event rather than directly assigning it to the window's event object.
"Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"