Welcome Guest, Not a member yet? Register   Sign In
close session on tab/window close

[eluser]Carlos Mora[/eluser]

I'm trying to close session when the user leaves the page, that is qhen he/she closes the window or tab.

With the session time set to 0, it will die by itself when browser closes, but to get the same in the case of tab close I'm trying to do using 'onunload' and validating every link, as sugested in stacloverflow site

questions 1921941 close-kill-the-session-when-the-browser-or-tab-is-closed 1986131

(sorry, system doesn't let me put urls)

It is working fine for anchors and submit's buttons, but i can't get it working for input type=[button]

var validNavigation = false;

function endSession() {
   window.alert('Debe loguearse!');
   // [removed] = 'PHPSESSID=; path=/';


function wireUpEvents() {

  window.onbeforeunload = function() {
      if (!validNavigation) {

  $("a").bind("click", function() {
     validNavigation = true;

  $("form").bind("submit", function() {
     validNavigation = true;

  $(":button").bind("submit", function() {
     validNavigation = true;

  $(":button").bind("click", function() {
     validNavigation = true;

// Wire up the events as soon as the DOM tree is ready
$(document).ready(function() {

the code for the buttons are :

<div class="form-row center">
                    &lt;input type="submit" value="Aceptar" /&gt;
                    &lt;input type="button" value="Cancelar"&gt;

The $(':button') is being selected right in all cases, because i checked that $(':button').length > 1.

The point is that my wanted 'onclick' to make the button valid is not working.

I'm making something wrong but i can't see it.

Messages In This Thread
close session on tab/window close - by El Forum - 12-21-2010, 10:37 AM

Theme © iAndrew 2016 - Forum software by © MyBB