views:

1078

answers:

1

hi,

Below function is working fine for IE, but not working for Mozilla and other browsers

   function CloseSession() {        
     alert("Inside Close");  
      if ((window.event.clientX < 0) || (window.event.clientY<0)) {  
        alert("Inside Events");  
        location.href = '/forms/sessionkill.aspx';  
      }    
   }

What I am trying to do is, I have a button on a page after clicking on that button, a page in opened in new window having session, the session will be maintained until user closes the browser. on the new page there is right navigation which have different links for different pages. If I directly call my sessionkill.aspx it kills the session whenever a link is clicked on window unload function.

+1  A: 

Mozilla does not set the global window.event property.

I'd recommend using an AJAX framework, such as JQuery (or even Microsoft AJAX).

function CloseSession(event) {   
  // use Mozilla event parameter, or window.event if that was not passed     
  event = event || window.event; 
  alert("Inside Close");  
  if ((event.clientX < 0) || (event.clientY<0)) {  
    alert("Inside Events");  
    location.href = '/forms/sessionkill.aspx';  
  }    
}

Update: if you were using JQuery:

function CloseSession(e) {   
  alert("Inside Close");  
  if ((e.pageX < 0) || (e.pageX < 0)) {  
    alert("Inside Events");  
    location.href = '/forms/sessionkill.aspx';  
  }    
}
samjudson
Dear can I have code for this ajax or jquery implementation
MKS
How can I use this function on window.onbeforeunload
MKS
The jquery example would be similar, except that event would be passed as a parameter (so no need for the check) and event.pageX and event.pageY instead of clientX and clientY. See: http://docs.jquery.com/Events/jQuery.Event
samjudson
above code is not working for mozilla its calling the function and first alert is called but alert("Inside Events") is not called. However working fine for IE
MKS
Can I have jquery solution for above problem
MKS
Why is it not working - well how about clientX and clientY is never less than 0. Try outputting these values before the if statement.
samjudson