/    Sign up×
Community /Pin to ProfileBookmark

unload function not working in Firefox and Chrome

Hi

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

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Sup3rkirbyMar 19.2014 — Playing with any unload scripts will typically leave you disappointed. Browsers all like to handle these sorts of things differently and there are a ton of restrictions.

But if you insist on using the events then I'd suggest taking a look at the [B]pageHide[/B] event for Firefox and Chrome. You'll want to add a check to make sure the event is supported, and then probably use the [B]addEventListener[/B] (and [B]attachEvent[/B] for IE8 and lower) to actually assign the event rather than directly assigning it to the window's event object.
Copy linkTweet thisAlerts:
@kirannauthorMar 20.2014 — Playing with any unload scripts will typically leave you disappointed. Browsers all like to handle these sorts of things differently and there are a ton of restrictions.

But if you insist on using the events then I'd suggest taking a look at the [B]pageHide[/B] event for Firefox and Chrome. You'll want to add a check to make sure the event is supported, and then probably use the [B]addEventListener[/B] (and [B]attachEvent[/B] for IE8 and lower) to actually assign the event rather than directly assigning it to the window's event object.[/QUOTE]


I tried like below but still this pagehide not working in FF and Chrome

window.addEventListener('pagehide', exit, false);

function exit() {

//submitting form to java application

}
×

Success!

Help @kirann spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...