473,395 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

need to perform ok as a cancel in event.returnValue

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
3 3273
acoder
16,027 Expert Mod 8TB
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
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
16,027 Expert Mod 8TB
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

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

Similar topics

5
by: Fred Brown | last post by:
Hi, I want to cancel a certain key in JavaScript. To do so, I catch the event in OnKeyPress and cancel the default: <head> .... function f(evt) { var evt = (evt) ? evt : ((window.event) ?...
1
by: Robert Nurse | last post by:
Hi All, I've got a form which I'm trying to submit automatically when the user has entered 2 or more characters in a text imput box. Here's my set up: <SCRIPT language="JavaScript1.2">...
3
by: sancha | last post by:
Hi, I need to promt the user when he moves away from the page by clicking an of the links available on the page. I was trying to use the onbeforeunload function but it seems it is a jScript...
1
by: Lars Netzel | last post by:
I really need to stop users from reposting the form with Enter or Return keys. It bypasses so many onClick validations that nothign works if they use Enter. I must force the user to CLICK on the...
1
by: Bucky | last post by:
I haven't found any vbscript code that can stop the form submission/postback after the msgbox. The problem is that asp:button is rendered as <input type="submit"> instead of <input type="button">....
1
by: PJ6 | last post by:
I have a table that changes its cell (input text) colors when their contents have changed (actually on keypress) and shows a couple of buttons automatically, UDPATE and CANCEL. This works...
1
by: dave | last post by:
What I am attempting to do is cancel an event in IE inside of my event handler, but the handler keeps getting called: for example if I do <div id="foo"> <div id="test">test text</div> </div>...
3
by: adbo_atoz | last post by:
Hello All I am trying to duplicate this code which works in IE to work in Firefox <SCRIPT LANGUAGE="javascript"> function submitOnEnterKey() { if(event.keyCode == 13) { event.returnValue...
10
by: Benton | last post by:
Hi there, I have a UserControl with a couple of textboxes and a couple of buttons ("Save" and "Cancel"). The Click event for this buttons is in the UserControl's codebehind of course, so here's...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.