开发者

database change after pressing 'X' button

What i know:- We can use Ajax to change database from javascript. So whenever we press the 'X' button on title bar it calls "onbeforeunload" event. And by this event we can change the database.

But in my case, i want to change the status of user only when user click开发者_Python百科 on 'X' button. Not in case of changing the page. As because changing the page is unloading the page. and closing the page is also unloading the page(As much i know).

Is there any way to differentiate between closing the page and moving from one page to other page?

I want to use it for changing the status of user(i.e. login/logout), whenever he presses cross button.

I don't want to set status "logout" when user changes the page. I want to set status "logout" when user 'X' the button.

Plese help me.


You cannot, in javascript, make a difference between an unload because of quitting and an unload because of navigating away.

What you can do:

  • On each unload, put a logoff
  • On each page, if the logoff was less than X time ago, remove the logoff.

This way, when a user navigates from one page to another, the "other" page will see the user and cancel the logoff.

PS: Don't rely on javascript for a 'log off' - users can disable it, or it can fail for various reasons. It might be useful to have a "last click" timestamp, and if the last click is too long ago, then consider the user as logged of.


Just use regular sessions storing login status of a user, not the database. By default, a PHP session expires when the browser is closed. See http://www.php.net/manual/en/session.configuration.php#ini.session.cookie-lifetime

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜