Search code examples
javascriptfirefoxsearchbar

How to prevent Firefox' in-site-search from popping up?


My problem is, is that the numpad's "/" key triggers the search bar in Firefox. I would like to prevent this from happening.

I'm currently working on an online Calculator, and ran into the problem described earlier. The reason why I would like this not to happen, is because you obviousely can't type in a division thanks to this feature. The page is only meant to run in Firefox, and it's just a little help for my little brother, so it doesnÄt have to be the most professional solution - if it works, it's fine. I've already tried the preventDefault method, but that doesn't change anything.

Any help is appreciated!

(Sorry if this question was already asked before, or it doesn't append to the rules, I'm totally new to StackOverflow)

window.addEventListener("keyup", function (event) {
    let signs = ["*", "-", "/", "+"];

    event.key.preventDefault;

    if (!(isNaN(event.key)) || signs.includes(event.key)) output.value += event.key;

    else if (event.keyCode === 8) {
      output.value = output.value.slice(0, -1);
    }
  })

//This is a snippet of my code right now, but the event.key.preventDefault part doesn't work for my problem

Solution

  • I think you should use preventDefault like this:

    event.preventDefault();
    

    I don't know whether this will block the search box or not, but you can call preventDefault like this.