javascriptjqueryfocusopera-mobile

Opera Mobile can't focus a text input with Javascript


Using Opera Mobile (tried 9.5 and 10), I cannot get the cursor inside a textbox using Javascript.

I have a barcode scanner so I wanted to have the textbox auto focused so that it's ready to receive the automated barcode input without the user having to tap. Having to tap is not really the issue, if the scanner tries to scan when a textbox is not in focus, Opera navigates to a local 'Welcome to Opera' page, even when the homepage setting is changed.

I've tried:

There's got to be a way to do ths with Opera Mobile. All other Javascript works no problem.


Solution

  • I've found a solution for this. I use an app called ScanWedge which inserts the scanned barcode into the textbox that has focus. The problem was I needed to get it in focus before the scan occured.

    In the ScanWedge settings, there is an option to send a prefix with the barcode and an option to enable escapes in the prefix (needs to be ON), I simply use a prefix of \x0D which means an enter keypress is sent before the barcode.

    This works because the focus() method highlights the textbox but does not insert the cursor, however if an enter key is pressed when the textbox is highlighted, the cursor is inserted.