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

need to perform ok as a cancel in event.returnValue

P: 2
Hi i am using the below code to close the window and i l get promt when click on 'X' button on ie browser with OK and Cancel buttons.

if i click ok window will be closed, if i click cancel window wont close.

what i need is if i click ok also it should perform as a cancel and the window should not close.

thanks in advance.

[HTML]<SCRIPT FOR = "window" EVENT = "onbeforeunload">
event.returnValue = "If you wish to keep this session alive, click the cancel button, open another browser window, and repeat your action.";
</SCRIPT>[/HTML]
Jan 10 '08 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
That OK is there for a reason, so that the user can choose to go his merry way without being forced to stay on the website.

Your use of onbeforeunload is IE-only and will not work with other browsers that also support it. Use something like:
Expand|Select|Wrap|Line Numbers
  1. window.onbeforeunload = confirmExit;
  2. function confirmExit() {
  3.     return "If you wish to keep this session alive, click the cancel button...";
  4. }
Jan 11 '08 #2

P: 2
That OK is there for a reason, so that the user can choose to go his merry way without being forced to stay on the website.

Your use of onbeforeunload is IE-only and will not work with other browsers that also support it. Use something like:
Expand|Select|Wrap|Line Numbers
  1. window.onbeforeunload = confirmExit;
  2. function confirmExit() {
  3.     return "If you wish to keep this session alive, click the cancel button...";
  4. }
Thanks for ur reply,

ur code not works.

here what i need is i want to disable the close 'X' button in IE6, and it is not possible.
instead of that i am writing event.returnValue=""; here i need to perform cancel operation if u click OK also.
Jan 11 '08 #3

acoder
Expert Mod 15k+
P: 16,027
ur code not works.

here what i need is i want to disable the close 'X' button in IE6, and it is not possible.
instead of that i am writing event.returnValue=""; here i need to perform cancel operation if u click OK also.
I know it doesn't work for that purpose. I was just giving you a cross-browser version for what you already have.

Let me explain again. If it were possible to make OK behave as cancel, it would be possible to prevent the user from ever leaving the site (which would be extremely annoying). They could disable JavaScript, of course, but it's annoying nonetheless.

You have no control over the OK and cancel buttons. The prompt itself appears automatically.

Why do you need this 'functionality'?
Jan 11 '08 #4

Post your reply

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