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 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2008
    Posts
    44
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Post Press a Keyboard key and make an action

    Code:
    Let's Play a bit<br>
    Press "A Key"<br><br>
    
    <script>
    var key = new Array();
    key['a'] = "javascript:window.defaultStatus='Hello!';"
    
    function getKey(keyStroke) {
    isNetscape=(document.layers);
    eventChooser = (isNetscape) ? keyStroke.which : event.keyCode;
    which = String.fromCharCode(eventChooser).toLowerCase();
    for (var i in key) if (which == i) window.location = key[i];
    }
    document.onkeypress = getKey;
    </script>

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    That looks like it is primarily written for Netscape 4.

    The only current browser it might work in is Internet Explorer - assuming you give the script permission to update the status bar.

    All other browsers would use keystroke.which but do not have document.layers
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New Coder
    Join Date
    Oct 2008
    Posts
    44
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Hi,

    Copy & Paste programing to help a member but it end up no where.

    Thanks

  • #4
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Unfortunately, the technology is ever-changing (and with a quickness, it sometimes seems), so even if you posted something that was more for current modern browsers, it might be considered obsolete in a year or three. At least, that's the way it seems, to me, with the current pace.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by WolfShade View Post
    Unfortunately, the technology is ever-changing (and with a quickness, it sometimes seems), so even if you posted something that was more for current modern browsers, it might be considered obsolete in a year or three. At least, that's the way it seems, to me, with the current pace.
    The biggest change I can see coming in the hopefully not too distant future is the death of Internet Explorer 8 and the removal of the need to support JScript as well as JavaScript - all the feature sensing code to detect whether to use the JavaScript or JScript version of calls can then disappear - eg there will no longer be a need to check for the JScript attachEvent command as all browsers will support JavaScript's addEventListener.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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