Results 1 to 8 of 8

Thread: Hot Keys

  1. #1
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Hot Keys

    Help me! I got a script from the Dynamic Drive that allows me to hot link a key to a web page. How can I do multiple keys?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Warning: Please include a link to the DD script in question in your post. See this thread for the proper posting format for asking a question.
    PLEASE: Include a link to your page that you want help with.

  3. #3
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'm looking at the script and it appears to have a bug. The demo doesn't work in NS7.2 or FF1.0.1. That being said, the following modified script will work in IE and older versions of NS as does the demo:

    Code:
    <script type="text/javascript">
    
    /*
    Hot Key Script- adapted from Home Hot Key Script-
    © Dynamic Drive (www.dynamicdrive.com)
    For full source code, installation instructions,
    100's more DHTML scripts, and Terms Of
    Use, visit dynamicdrive.com
    */
    
    //configure keys, use as many as you like:
    keys="dyg"
    //configure destinations, one for each key,
    //if you break a line here, do it after a comma:
    dest=["http://www.dynamicdrive.com","http://www.yahoo.com",
    "http://www.google.com"]
    //No need to edit beyond here//
    if (document.layers)
    document.captureEvents(Event.KEYPRESS)
    function go_dest(e){
    for (i = 0; i < dest.length; i++){
    if (document.layers){
    if (e.which==keys.charCodeAt(i))
    window.location=dest[i]
    }
    else if (document.all){
    if (event.keyCode==keys.charCodeAt(i))
    window.location=dest[i]
    }
    }
    }
    
    document.onkeypress=go_dest
    
    </script>

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Here's one that works in IE6 NS7.2 NN4.79 FF1.0.1, But notice the body 'onkeypress' event handler!

    HTML Code:
    <html>
    <head>
    <title>Keypress</title>
    <script type="text/javascript">
    
    /*
    Hot Key Script- adapted from Home Hot Key Script-
    © Dynamic Drive (www.dynamicdrive.com)
    For full source code, installation instructions,
    100's more DHTML scripts, and Terms Of
    Use, visit dynamicdrive.com
    */
    
    //configure keys, use as many as you like:
    keys="dyg"
    //configure destinations, one for each key,
    //if you break a line here, do it after a comma:
    dest=["http://www.dynamicdrive.com","http://www.yahoo.com",
    "http://www.google.com"]
    //No need to edit beyond here//
    if (document.layers)
    document.captureEvents(Event.KEYPRESS)
    function go_dest(e){
    for (i = 0; i < dest.length; i++){
    if (document.layers){
    if (e.which==keys.charCodeAt(i))
    window.location=dest[i]
    }
    else if (document.all){
    if (event.keyCode==keys.charCodeAt(i))
    window.location=dest[i]
    }
    else if ((document.getElementById)&&(!document.all)){
    if (e==keys.charCodeAt(i))
    window.location=dest[i]
    }
    }
    }
    
    document.onkeypress=go_dest
    </script>
    </head>
    <body onkeypress="if ((document.getElementById)&&(!document.all)){go_dest(event.which)}">
    </body>
    </html>

  6. #6
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1
    Here's one that works in IE6 NS7.2 NN4.79 FF1.0.1, But notice the body 'onkeypress' event handler!
    Be careful when fiddling with keys. You might end up overriding an application key. For example, I might press Ctrl+H in Firefox to bring up my browsing history. If you've bound a URL to H, the History side-bar will open but I'll lose my current page. Also, what if I'm typing in a form control?

    Mike

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by mwinter
    Be careful when fiddling with keys . . .
    Good point Mike, I thought this was a somewhat silly script to begin with but, it is what the OP asked for.

  8. #8
    Join Date
    Mar 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your help

Bookmarks

Posting Permissions

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