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

[eluser]Carlos Mora[/eluser]
Hi,

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]

Code:
var validNavigation = false;

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

}

function wireUpEvents() {

  window.onbeforeunload = function() {
      if (!validNavigation) {
         endSession();
      }
  }

  $("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() {
    wireUpEvents();
});

the code for the buttons are :

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

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.




Theme © iAndrew 2016 - Forum software by © MyBB