Scan inputs with Opera Mobile 10

别等时光非礼了梦想. 提交于 2019-12-04 11:56:10

问题


We have chosen the Opera Mobile for one PDA application, everything went well until we hit a problem with regards to taking a scanned input to one of the text fields.

The general way you'd approach this problem is by setting one textBox to have focus when the scan operation is performed.

UNFORTUNATELY, intentionally or unintentionally Opera is not supporting this. The focus is no-where when you enter in to the screen and there is no way of explicitely setting it. Worst comes next, you cannot detect the key-press events too, which makes it virtually impossible to take the input event from the scan operation.

I have no clue why Opera, one of the best acclaimed mobile browsers, does not support this.

These are the places the same question is asked over and over again,

http://dev.opera.com/forums/topic/255066

http://dev.opera.com/forums/topic/650332

http://dev.opera.com/forums/topic/384311

We have posted in the Opera Dev forum as well and it seems that they (so far) have no solution for this. If anyone has tried a workaround, we would be interested to hear the solution.

And please note that the solution in here is not working in Opera Mobile 10. I have not tried it in the proposed 9.X version.


回答1:


I found it myself. And here is how to do it.

Have a hidden button in the form

input type="button" id='myHiddenButton' visible='false' onclick="javascript:doFocus();" width='1px' style="display:none"

Have a javascript to get fired on the click event of the hidden button.

     function doFocus() {
         var focusElementId = "MyTextBox"
         var textBox = document.getElementById(focusElementId);
         textBox.focus();
     }

Have the button clicked using a javascript at the end of the document

     function clickButton() {
         document.getElementById('myHiddenButton').click();
     }

     setTimeout("clickButton()", 100);


来源:https://stackoverflow.com/questions/5776484/scan-inputs-with-opera-mobile-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!