简体   繁体   中英

window.confirm - space vs enter key on Cancel button

I've stumbled upon a strange issue and I have two questions: 1) is it a bug in browsers` implementation (checked in Chrome, Firefox, Safari)?; 2) is there a workaround available?

Steps to reproduce:

  1. User window.confirm()
  2. Navigate the popup and use Space/Enter key on visible buttons.

And here's the results:

  1. Hitting enter key on OK button - returns true
  2. Hitting space key on OK button - returns true
  3. Hitting space key on Cancel button - returns false
  4. Hitting enter key on Cancel button - returns true

The last case is the one I'm wondering about. Why targeting Cancel button with an enter key is equal to hitting OK button? I haven't found any hint in the spec: https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-confirm

This is a standard UI convention for Yes/No dialog boxes that should be consistent across your operating system. It is nothing specific to JavaScript prompts.

Space activates the focused button.

Enter actives that default button.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM