How can I add a Javascript listener to capture input from bluetooth barcode scanner to iPad?

后端 未结 2 709
我在风中等你
我在风中等你 2020-12-06 03:44

I\'m having trouble logging keystrokes in javascript on the iPad. The following script works on Chrome and Safari, but not iPad Safari. The bluetooth barcode scanner sends 1

2条回答
  •  广开言路
    2020-12-06 04:01

    Safari for iOS doesn't trigger keyboard events on DOM elements that are not components of a form. This includes the document and body which are usually used to capture keystrokes anywhere on the page.

    The only way to trigger a keystroke event on document or body of a page is to trigger it in an input or textarea. In that case, the event will correctly 'bubble' to the body and document.

    However, this might be a problem because Safari for iOS doesn't allow us to give an element focus from javascript.

    At the moment, we are using a solution where user has to click on an input field before starting the first scan, and the input field is then moved off-screen but retains focus.

    If someone has a better solution, please share.

提交回复
热议问题