"onunload is unreliable in all browsers except IE. Also, since you are using jQuery, there is no need to have any inline JavaScript." . . . .