24SevenOffice

Ajax-based ERP/CRM with accounting, invoicing, crm, calendar, e-mail and more.

A Javascript ‘window.confirm’ improvement?

How can we actually improve the confirmation dialog? Is it even possible? Before I will disappoint someone, I have to say I haven't found a solution for a cross-browser confirmation dialog. I will rather tell you about my experiences. A confirmation dialog will halt all code-execution until a user input is done. This is actually the major breakdown. Only IE supports a way to wait for user input by using "showModalDialog", as far as I know this is not possible in either FireFox or Opera. A few basic statements; The confirmation dialog is a function that returns a value. A function will halt the code-execution until the functions returns a value or reachs the end of the function. Can we emulate a confirmation dialog just by delaying the return?

My first thought by delaying a return was by using "setTimeout", but what we need is a blocking-delay, where "setTimeout" will come to short. A blocking-delay could be done by using a loop to simulate a sleep method, but this will be too far CPU intensive - also a very bad practice. A recursive call may also be too far CPU intensive, and to many recursive calls will not be allowed. The code-snippet below is certainly not the way to go but it will demonstrate what I intend to do: If there is a solution for this (it probably is but I haven't found it) we could use a normal dialog window like "window.open" to simulate the confirmation dialog for non-IE browsers, as "showModalDialog" is the best way to go for IE browsers. The purpose of making a improvement of the confirmation box is to make it more user-friendly, the original confirmation box is lacking of features like button configuration, use of colors in the caption etc. The screenshot is an example of the improvement for IE browsers compared to the built-in confirmation dialog. There is always ways to work around, but none of the solutions will work as nice as the one in IE by using showModalDialog. The solution is very flexible since you can easily setup the style as you want, in a similar way as the "MsgBox" method in Visual Basic 6.For examples of how this works you can go to this page or download the source. You are welcome to contribute with solutions for this, and I will do my best to work out a nice solution for cross-browser - if it hasn't been done already.

1 Comment(s)

  1. Comment by Thomas Hansen on September 1, 2007 13.13

    This is actually very easy using Gaia, you just create a Gaia Window in e.g. a UserControl which you have to event handlers for, one caled OnOK another called OnCancel and you’re expected to supply event handlers for both of these events when creating the UserControl…

    .t

Comments RSS TrackBack Identifier URI

Leave a comment