简体   繁体   中英

Javascript function not working in Mozilla

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.

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';  
  }    
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM