views:

152

answers:

3

Hello,

Is there a way to know that the user is closing the navigator, and/or the tab in Safari for iPhone, so that I can save data to localStorage, or do I need to do it for every input ?

A: 

Okay, it seems like onbeforeunload is a Microsoft invention, and so is not supported by Safari nor Opera.

I'm going to have to look for another way :)

rnaud
A: 

Did you try the unload event?

jQuery documentation on the unload event

Vincent Robert
I just did, it does not work
rnaud
+1  A: 

Having looked at the documentation for localStorage, I think you need to be storing the relevant data as it's generated/modified rather than waiting for a close event. I realise this is probably more work than any of us would like but at least you can be sure that you are saving the current state at each point so that even a browser crash shouldn't kill your state.

Lazarus
By the way, I went with local database instead of localStorage, which is much more helpful for the kind of data i'm using.
rnaud