PDA

View Full Version : type a letter to execute?



resin
Jun 16th, 2012, 09:00 PM
Not sure if this is even possible or if it would cause any conflicts, but I was wondering if you can trigger an event by typing a certain character. For instance, I type 'U' and a specified URL will load in the browser. Is there a way to do this?

Old Pedant
Jun 16th, 2012, 09:19 PM
Sure.

Just attach the onkeypress even to the <body> of your page and have it check for the letter(s) you are looking for.

If you want it to work cross browser, you have to handle the even in both the normal and the MSIE-pre-version-9 ways.

But caution: If you also have (for example) <input> form fields then typing a "U" even in them will trigger the action unless you suppress the event bubbling.