I know there is a very similiar question (JavaScript: How to select "Cancel" by default in confirm box?) on this site, but I felt like I did not get a good answer out of that one as my premises are not the same.
Problem description: I am writing a web browser Javascript popup window that is supposed to take some information as input and the user can choose between "OK" to process the information and continue with whatever, or "Cancel" to close the window and go back to whatever. So far so good. The problem is that some users press "X" in the upper right corner of the popup to close the window (either by mistake or actually believing that the data is processed) and get a second dialog popup (you cannot change the text in this dialog) displaying "Are you sure you want to navigate away from this page?" - "Press OK to continue, or Cancel to stay on the current page" - OK/Cancel... Now, some of the users just press enter on their keyboard and oops, the popup is closed and all information is lost.
Question: Can you, or is there a workaround to set focus on "Cancel" instead of "OK" when it es to the dialog of whether to close an Internet Explorer popup/tab or not?
Thank you in advance! =)
I know there is a very similiar question (JavaScript: How to select "Cancel" by default in confirm box?) on this site, but I felt like I did not get a good answer out of that one as my premises are not the same.
Problem description: I am writing a web browser Javascript popup window that is supposed to take some information as input and the user can choose between "OK" to process the information and continue with whatever, or "Cancel" to close the window and go back to whatever. So far so good. The problem is that some users press "X" in the upper right corner of the popup to close the window (either by mistake or actually believing that the data is processed) and get a second dialog popup (you cannot change the text in this dialog) displaying "Are you sure you want to navigate away from this page?" - "Press OK to continue, or Cancel to stay on the current page" - OK/Cancel... Now, some of the users just press enter on their keyboard and oops, the popup is closed and all information is lost.
Question: Can you, or is there a workaround to set focus on "Cancel" instead of "OK" when it es to the dialog of whether to close an Internet Explorer popup/tab or not?
Thank you in advance! =)
Share Improve this question edited May 23, 2017 at 11:54 CommunityBot 11 silver badge asked Mar 26, 2012 at 10:27 Mr BaloonMr Baloon 2,7764 gold badges38 silver badges53 bronze badges 4- I think the scenario makes it very clear that popup dialog boxes are horrible UI that doesn't fit your users. Have you considered other methods? – Deestan Commented Mar 26, 2012 at 11:16
- Well, this dialog is part of IE and something that I (as far as I know) cannot really control. One thing that would help me though, would be if there was a way to control the default behaviour of this particular dialog. – Mr Baloon Commented Mar 26, 2012 at 11:22
- 1 I meant requiring data entry through some other means than the initial popup. Like, a pass-through-page. -- Alternatively, create a in-page shim-"popup" in JavaScript - without an "X" button. – Deestan Commented Mar 26, 2012 at 11:25
-
Do you mean when you say that you're "writing a web browser javascript popup window" that you're using the
prompt(,)
js function in your app? – Daniel Imms Commented Apr 2, 2012 at 21:57
1 Answer
Reset to default 4Unfortunately, I don't think it's possible to change focus on browser-generated dialog boxes.
As Deestan suggested, maybe you can create a faux popup using js and css, and do whatever you want in terms of styling it, and still have the user enter information, and have the information passed to your code.
From what i've heard/read, it's generally accepted that using alert() or popup() for anything other than debugging is frowned upon.