better cross-browser beforeunload