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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Responsive Web

From novice to tech pro — start learning today.