/    Sign up×
Community /Pin to ProfileBookmark

How to track window event value.

Hi All,
I need to show the alert message when the user close the browser by clicking X button on the window(I mean top right button on the window).

I have done that by using the following code,

if (event && event.clientX && event.clientY < 0) {
event.returnValue=”Are U Sure??”
}

It works fine, here the problem is it shows the alert message with this text, I want to get what the user clicked , OK or CANCEL. Bcos based on that I need to do some business process.

Can anybody know how to get what button user clicked. I tried using confirm , but it didn’t work.

your help will be appreciated.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@mityaAug 05.2009 — If I understand you correctly, you need confirm, yes.

Confirms are handled as booleans - true if OK is pressed, false if cancel.
Copy linkTweet thisAlerts:
@kishansauthorAug 06.2009 — No , It won't work. I tried. If you use confirm then if u click OK or Cancel in confirm window then also it closes the browser regardless of which button you clicked.
×

Success!

Help @kishans 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.18,
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,
)...