Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm fairly surprised by that (and expect you'll find the behavior varies from browser to browser), but <code>alert</code> is a funny beast somewhat at odds with the rest of the browser environment, so...</p> <p>Since you always want to stop the default behavior, I'd recommend either:</p> <ol> <li><p>Don't use <code>alert</code>, which is fairly ugly anyway (use any of the many "modal" dialog plug-ins for jQuery, or just do your own with a styled, absolutely-positioned <code>div</code>), or</p></li> <li><p>Take the <code>alert</code> out of the event handling sequence, like this:</p> <pre><code>var onEnter = function (values) { $("#" + values['id']).keydown(function (e) { if (e.which == 13) { setTimeout(finishHandling, 0); return false; } function finishHandling() { var function_to_call = window[values['function']]; if (typeof function_to_call === 'function') { if (values['parameters'] != null) { parameters = values['parameters']; var args; if (typeof parameters === 'string') args = parameters.split(','); else args = new Array(parameters); function_to_call.apply(window, args); } else function_to_call(); } } }); } </code></pre> <p>What this second option does is let the event handler complete before you call <code>alert</code>, by scheduling a callback to <code>finishHandling</code> to occur almost immediately, but after the event handling has been completed. (I also removed the call to <code>event.preventDefault()</code>, because <code>return false;</code> from a jQuery event handler does both <code>event.preventDefault()</code> and <code>event.stopPropagation()</code>. You may have needed it when the <code>alert</code> was there, but you don't without it.)</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload