Leaving a window

Javascript coding ..

Moderators: macek, egami, gesf

victor123
New php-forum User
New php-forum User
Posts: 192
Joined: Mon Sep 06, 2004 1:23 am
Location: Madrid, Spain

Leaving a window

Postby victor123 » Mon Jul 11, 2005 2:02 am

Hi,

I would like to execute certain code only when a user leaves a window by closing the navigator. I have been looking at some events such as onUnload, but that does not do what i want since it executes every time the user leaves the window (going to another page and such).

Is there any way of performing this?

Thanks in advance.

User avatar
gesf
Moderator
Moderator
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Postby gesf » Mon Jul 11, 2005 10:41 am

Hunn... only using sessions.
Use session_set_save_handler() to set your session handler functions and then use the "session close" method for what you need.

victor123
New php-forum User
New php-forum User
Posts: 192
Joined: Mon Sep 06, 2004 1:23 am
Location: Madrid, Spain

Postby victor123 » Mon Jul 11, 2005 11:36 pm

Hmmm... but when would that "session close" method be called? you have to call it explicitly or is it called automatically when the navigator window is closed?

Thanks again.

User avatar
gesf
Moderator
Moderator
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Postby gesf » Tue Jul 12, 2005 5:04 pm

It is called automatically.
Example:

Code: Select all

<?php

// sess_destroy function somewhere
// in your files, included or not...
function sess_destroy($key) {
       $query = "DELETE FROM sessions WHERE sessionID = '$key'";
       mysql_query($query);
       return true;
}

// ....

// Setting session handler functions
session_set_save_handler (
     "sess_open",
     "sess_close",
     "sess_read",
     "sess_write",
     "sess_destroy",
     "sess_gc"
);

session_start();

// do some stuff ...

session_destroy();

?>
Please take a look at the session_set_save_handler() page of the manual.


Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 1 guest