- From: Ben Rimmington <benrimmington@me.com>
- Date: Sun, 27 Feb 2011 08:57:08 +0000
> On Sat, Feb 26, 2011 at 2:29 PM, Ben Rimmington <benrimmington at me.com> wrote: > >> <http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#simple-dialogs> >> >> An optional callback parameter could be added to the simple dialogs API: >> >>> result = window.alert(message, [callback]); >>> >>> result = window.confirm(message, [callback]); >>> >>> result = window.prompt(message, [default], [callback]); >> >> If the callback argument is recognised as a function value: >> >> * the result is the supplied callback; >> >> * the callee returns without waiting for user input; >> >> * the callback is invoked after the dialog is dismissed. >> >> Otherwise [see current spec]: >> >> * the callee simply ignores the callback argument; >> >> * the script is paused until the dialog is dismissed; >> >> * the result is undefined, boolean, string or null. I originally thought that the simple dialogs API, as part of the new HTML spec, should be improved if possible. But I've changed my mind -- I suspect that experienced developers will continue to avoid using the API. On 27 Feb 2011, at 00:08, Adam Barth wrote: >> For user agents that don't support the updated API: >> >>> function promptWrapper(message, default, callback) { >>> var result = window.prompt(message, default, callback); >>> if (callback && (typeof callback === "function")) { >>> if (result !== callback) { >>> callback(result); >>> } >>> return callback; >>> } >>> return result; >>> } > > Of course, that would be a synchronous callback rather than an async one... That's true, a compatibility layer such as promptWrapper() would need to use window.setTimeout() for an async callback. The example code was mainly intended to show how "feature detection" of the non-blocking mode could be implemented.
Received on Sunday, 27 February 2011 00:57:08 UTC