« General Introduction to LaTeX
Waiting in for a Parcel (Again) »

Trigger onKeydown Without Activating Firefox Quick Search

Whilst working on ImpAmp, I was attempting to catch when the user typed ' or / into the window without activating the firefox quick search. After hunting around on the web, I found lots of places telling me how to deactivate it permanently which is not what I want. Normally I find it very useful, just not when running ImpAmp. The solution that I found involved typing into a text-box. The quick search is disabled when typing in a form yet onkeydown still accepts the input. So I created a form at the bottom of my page:

<form action="javascript:void(0);" method="get" id="hiddenForm">
<p><input type="text" name="in" value="" id="theBox"></p>
</form>

I had tried to make the box hidden but then the box couldn't gain focus and failed to work completely. Instead, I applied some css so the user wouldn't notice it. This throws the form off the screen.

#hiddenForm {
  position:absolute;
  left:-999px;
  top:-999px;
  }

So this method worked nicely until the input box loses focus. To ensure the box retains focus, add a function called by onkeyup which refocuses on the input box. I was also worried that the box might fill up, so I added another command that will empty the box.

document.onkeyup = function keyPress(event) {
  document.getElementById('theBox').focus();
  document.getElementById('theBox').value='';
}
Go Top
Previous:
« General Introduction to LaTeX
Next:
Waiting in for a Parcel (Again) »

Comments

I would love to know what you think. To comment on this article, send me an email

No comments yet.