最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to hide soft keyboard and keep input on focus - Stack Overflow

programmeradmin0浏览0评论

I have a page for a barcode scanner(honeywell ct50) running Android 4.4.4, The soft keyboard pops up automatically as input textbox is on focus. Is there any solution to hide it? I have read suggestions, mostly making the input losing focus or being readonly, but I need to keep the focus on the input to read the barcode.

I tried 1. to execute event.preventDefault() in onfocus event, it doesn't work. 2. to get the barcode on document.keypress(), the solution in the post as below, but nothing got from my scanner. javascript - hide mobile default keyboard but keep input field active

Any ideas are wele.

I have a page for a barcode scanner(honeywell ct50) running Android 4.4.4, The soft keyboard pops up automatically as input textbox is on focus. Is there any solution to hide it? I have read suggestions, mostly making the input losing focus or being readonly, but I need to keep the focus on the input to read the barcode.

I tried 1. to execute event.preventDefault() in onfocus event, it doesn't work. 2. to get the barcode on document.keypress(), the solution in the post as below, but nothing got from my scanner. javascript - hide mobile default keyboard but keep input field active

Any ideas are wele.

Share Improve this question asked Feb 6, 2018 at 4:29 Charlene FengCharlene Feng 811 silver badge3 bronze badges 2
  • why are you referring to javascript? Is it not a native application? – Chisko Commented Feb 6, 2018 at 5:05
  • 1 Have you found a solution, we've ran into the same problem in a Web App that uses barcode scanner on the same device and need to hide the keyboard while keeping focus on a text field – pixelwiz Commented Jun 8, 2018 at 13:33
Add a ment  | 

2 Answers 2

Reset to default 5

Old topic but this is the solution which works at least for android 6 and 7:

yourInput = document.getElementById('yourInputElement');
yourInput.readOnly = true;
yourInput.focus();
setTimeout(function(){document.getElementById('yourInputElement').readOnly = false;}, 50);

You put your input in readOnly = true before the focus.
The keyboard will not appear.
And you put back the input in readOnly = false but not immediately.
So you can use your scanner without having the keyboard popping up.

For me what worked at some point was setting the ion-input type="text" to readonly, but now it is not working when setting that property. Maybe give it a try.

发布评论

评论列表(0)

  1. 暂无评论