Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Nov 2011
    Posts
    154
    Thanks
    5
    Thanked 0 Times in 0 Posts

    type a letter to execute?

    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?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,166
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •