onUnload and onbeforeUnload events not firing

Hi folks,

Any ideas why the onUnLoadFunction(); is NOT called in Mobile Safari in iOS7. This functions is called in all browsers EXCEPT Mobile Safari on iOS7.

Any Ideas?

window.onunload = window.onbeforeunload = (function(){
var saveInLMS=false;
return function(){

if (saveInLMS) return;


Open in new window

Who is Participating?
COBOLdinosaurConnect With a Mentor Commented:
I don't have a workaround.  I think you are walking on a thin edge relying on the unload to send data; there are a lot of ways that it could go wrong.  You basically seem to be running into an issue that could become more common across devices as privacy, usability and accessibility issues trump developer convenience and support for the event becomes a negative for the browser and device manufacturers.

onunload() is not supported by Safari mobile.  I think Opera on mobile also has the same issue. It works most of the time in other browsers, but virtually all implementations have some buggy behavour; and it is an event that should not even be in the standard because of its potential for abuse; and interference with user rights.

rgarimellaAuthor Commented:
How about onbeforeUnload ?

How do i call a function when Mobile Safari window closes ?
The only thing I have seen show up in research for both unload and beforeunload is that they do not work for safari on mobile.

Generally when a user closes a window, they want to close it; so most developers consider it bad practice to interfere with the exit.  What is it that you think is so critical that that you have to grab your users by the throat and prevent them from a clean exit?

rgarimellaAuthor Commented:
I have a SCORM course that works on a Learning Management System. So the code that I have sends information to the LMS when a users exits a course/closes the tab/window I need to send information to the LMS, on which page the user had exited and send some cleanup code.

I have the code working in ALL the browsers including iOS6 mobile safari. But for some reason the same code DOES NOT work in iOS7 mobile safari.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.