Link to home
Start Free TrialLog in
Avatar of rgarimella
rgarimella

asked on

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;
   saveInLMS=true;
   onUnLoadFunction();
}

}());

Open in new window

Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

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.

Cd&
Avatar of rgarimella
rgarimella

ASKER

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?

Cd&
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.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial