By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,627 Members | 1,149 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,627 IT Pros & Developers. It's quick & easy.

alerting window while closing mainwindow using java script

100+
P: 121
Hi,

Please help me,
Here i have a problem
When i am trying to close the main browser i need to popup a confirmation window
actually i had a code that is working on IE browser with some issues

Here is my code
[HTML]<html>
<head>
<script type='text/javascript'>
var browserName=navigator.appName;
if (browserName=="Microsoft Internet Explorer")
{
function onBeforeUnloadAction(){
return "With Out Logout You Cann't Login Again!";
}
window.onbeforeunload = function(){
if((window.event.clientX<=-1) ||(window.event.clientY<=-1)){
return onBeforeUnloadAction();
alert(onBeforeUnloadAction());
}

}
}
</script>
</head>
<body >
</body>
</html>
[/HTML]
But i have a problem in above program which should not happen
1.While refreshing the browser by pressing the refresh button and pressing the back button in the IE browser.

and I should make it work on mizilla also

2. In the Mizilla browser it is not working i need to be work on this browser also

3.It should populate when and only i pressed on window close button


Please any body give me suggesion

Thanking you,
Jan 19 '08 #1
Share this Question
Share on Google+
5 Replies


gits
Expert Mod 5K+
P: 5,333
hi ...

the onbeforeunload event is used by mozilla too ... so simply remove your browserdetection and it should work for both of the browsers ...

the other problem you have is tricky ... may be you could check the location.href of the window to differ between reload, back or close-actions but i'm not sure ...

kind regards
Jan 19 '08 #2

100+
P: 121
hi ...

the onbeforeunload event is used by mozilla too ... so simply remove your browserdetection and it should work for both of the browsers ...

the other problem you have is tricky ... may be you could check the location.href of the window to differ between reload, back or close-actions but i'm not sure ...

kind regards
Thanks for replay,

i am able getting the alert window while closing the window but there is one problem for me this is working on IE and Mozilla as well.

Only problem is while iam clicking the refresh button ,Back button and as well as Home button on the browser The same alert box is popuping

For this what should i do??
Please help me....
thanking you,
Jan 21 '08 #3

gits
Expert Mod 5K+
P: 5,333
hi ...

after some more research i'm convinced that there is no possibility to capture that events that are triggered by those buttons (back, next, refresh, home). could you tell what purpose the function serves? may be we find a workaround for the problem ...

kind regards
Jan 21 '08 #4

100+
P: 121
hi ...

after some more research i'm convinced that there is no possibility to capture that events that are triggered by those buttons (back, next, refresh, home). could you tell what purpose the function serves? may be we find a workaround for the problem ...

kind regards
Hi,
Thanks for your reply,Iam sorry for the late ..

Let i will explain here deeply

i have an application which is having login page
if i have logged in into my application by successfully means with proper login information
So in my login database i have three defferent fields which are going to update or insert every time when i was logged in our logged out

in the database table i have flag. iam setting the flags based on defferent situations those are

if i loggedin,then in the databse table the flag will set with 1.
if i loggedout ,then in thedatabase tablethe flag will set with 0.

What is the purpose of flag...??
Here iam explaining
to avoid multiple logins with same user from any system...

So in this case we should compulsory logout.

If trying to close the application without logout.
At that point iam populating one window which provides to loggout from the application...
Jan 22 '08 #5

gits
Expert Mod 5K+
P: 5,333
hi ...

in case you have set the flag you should be able to tell the user to logout explictly the next time ... and relogin him then ... it would be the same problem when he doesn't close his browser at work ... may be over the weekend ... and tries to login at home again from another machine? ...

kind regards
Jan 22 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.