开发者

alternative to onbeforeunload

I want to update database when user leave the site. I am using php for my site. I am using javascript function onbeforeunload and call php through ajax to update database.

Now the problem is that the fu开发者_运维百科nction onbeforeunload is not supported by Opera and Safari, and so the entry should be deleted from database is still over their and affect my database and site.

Any idea or suggestion what i can do?


onbeforeunload seems to be a proprietary function from Microsoft. Firefox implemented it while Safari and Opera didn't.
http://www.designerstalk.com/forums/help-me/46310-onbeforeunload-safari-issues.html

Try the window.onunload event instead.
https://developer.mozilla.org/en/DOM/window.onunload

Example:

function unloadPage() {
   alert("unload event detected!");
}
window.onunload = unloadPage;


OnBeforeUnload is supported in Safari - what is not supported is the use of AJAX ... you need to use a Synchronous call - you can use alert to verify this.....


onbeforeunload should work in Safari. See Can I pop up a confirmation dialog when the user is closing the window in Safari/Chrome? (I just tested in Google Chrome and it works)


Beacon API (experimental technology) seems suitable for this kind of tasks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜