javascript - Save state using HTML5 Web SQL on window unload -


I am using Web SQL API to store some information on one page; I want to save the position of the page when the user closes the page or navigates away, thus, I start with:

  window.onunload = function () { Db.transaction (function (tx) {executeSql ("state underlying (values) (?)", [Foo]);}); };  

However, it is asynchronous, so it is not complete before the page ends

I unsatisfied one (fraudulent, because it has not happened yet) By adding alerts ("saved!"); My resolves at the end of the window. Onunload, which does not give DB an opportunity to talk to me, but until I can escape from it, I should not be of the warning unless there is a delay in loading.

Any thoughts? I need to block the thread calling the onunload function for a moment, which alerts.

( BTW, openDatabaseSync version to stop any suggestions that I use synchronous, this API is envisaged and implemented for webworkers, window Not for the object.)

Do you have access to WebSockets?

Can you hear on the socket, and then when it takes time to unload, then connect to that hearing socket, when the listener receives a connection from synchronous, then it is included in starts and closes the connection after the query ends.

This is the only thing I could think of, and I'm not sure these interfaces support this kind of use. I asked if I had a server, how would I do this: I would use a synchronous network connection on the server to write state.

Besides, I'm not sure that the unload event may be blocked for an indefinite period of time, but for some "Googling synchronous Ajax" it suggests that it can be.

7/19 10:26 Update PDT

Browsers are sending the webSocket only, you can not open a socket for listening.


Comments