change onbeforeunload to onunload for wider compatibility