1

If I type Japanese characters into the search field, is it feasible to hide the IME suggestions so that I can easily choose the proper search suggestion using my keyboard. I still want to be able to translate special characters between alphabets using the IME. I only want to disable type-ahead suggestions from the IME. Does anyone know how to do programmatically using javascript or html to stop certain fields on a web page from displaying the IME suggestions?

I tried the css property ime-mode but is deprecated and not supported by all browsers.

Krina
  • 19
  • 1

3 Answers3

0

I'm afraid you cannot do this by JavaScript/HTML5 because IME is a system software whose candidate (suggestion) window is rendered as a local UI element.It should be a security concern if page scripts could modify the behavior of your local system.

What the browser can do for you is to trigger some IME-related eventes (e.g. compositionstart, compositionend) to help cooperate with IME software behaviors (e.g., show IME UI at the correct position) to complete features in the page.

Jaytalent
  • 41
  • 4
0

It seems that an Input Method Editor API was considered in the past, but currently none are available in browsers.

Limited to Chrome (or Chromium, Edge ...), <input type="search"> might be the behavior you want.

see. https://stackoverflow.com/a/75679659/21359941

tinsep19
  • 1
  • 1
0

It is doable but you need a separate (hidden) element to handle keyboard input which is going to act as a proxy for IME composition (resp. for input).

In this hidden field, you can simply hook on "keyup" event and reset the current value to an empty string which practically stops the IME composition.

hiddenInputElement.addEventListener("keyup", () => {
    hiddenInputElement.value = "";
});

Note #1: By doing so, you need to also handle everything else manually, so you're responsible for e.g. recognising when input is finished and inserting it programatically into your main field.

Note #2: It'll force you to handle different lifecycles that each browser has in terms of input/IME events.

Martin Janíček
  • 444
  • 1
  • 6
  • 13