I am trying to handle window or browser close event with javascript to invalidate the session. Following is the code

window.onunload = function(e) {
e = e || window.event;
var y = e.pageY || e.clientY;
if(y < 0){
//call to java class to handle session

This snippet is working with IE but not in FireFox(version 23) and chrome(Version 33)

I tried onbeforeunload function which is working for all browsers but it is invoking even for refresh also which i don't require.

Please suggest me to accomplish this issue..

thanks inadvance