Results 1 to 5 of 5

Thread: Having trouble with Hot Key script

  1. #1
    Join Date
    Oct 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Having trouble with Hot Key script

    1) Script Title: Home HOt Key Script

    2) Script URL (on DD):http://www.dynamicdrive.com/dynamicindex5/button1.htm

    3) Describe problem: I'm trying to put this in my page so when users click on the letter h they go back to the homepage of the site. When I put it into the <head> of my page and then preview the page in my browser (tried IE7 and FF) it doesn't work. I tried using it with the original site (dynamicdrive.com) and it worked fined. But when I put my site in it doesn't do anything. I used the wizard it provided and the code var hotkey= was blank as compared to 104 which came after the first time. I don't know if this would help or not. Any tips on how to get it to work with other sites would be very appreciated.

    Code First Time
    <script language="JavaScript1.2">

    /*
    Home Hot Key Script-
    &#169; Dynamic Drive (www.dynamicdrive.com)
    For full source code, installation instructions,
    100's more DHTML scripts, and Terms Of
    Use, visit dynamicdrive.com
    */

    var hotkey=104
    var destination="http://www.dynamicdrive.com"
    if (document.layers)
    document.captureEvents(Event.KEYPRESS)
    function backhome(e){
    if (document.layers){
    if (e.which==hotkey)
    window.location=destination
    }
    else if (document.all){
    if (event.keyCode==hotkey)
    window.location=destination
    }
    }
    document.onkeypress=backhome

    </script>


    Code Second Time

    <script language="JavaScript1.2">

    /*
    Home Hot Key Script-
    &#169; Dynamic Drive (www.dynamicdrive.com)
    For full source code, installation instructions,
    100's more DHTML scripts, and Terms Of
    Use, visit dynamicdrive.com
    */

    var hotkey=
    var destination="http://www.dynamicdrive.com"
    if (document.layers)
    document.captureEvents(Event.KEYPRESS)
    function backhome(e){
    if (document.layers){
    if (e.which==hotkey)
    window.location=destination
    }
    else if (document.all){
    if (event.keyCode==hotkey)
    window.location=destination
    }
    }
    document.onkeypress=backhome

    </script>



    I replaced the var destination with my site's URL
    Thanks once again

  2. #2
    Join Date
    Aug 2004
    Posts
    10,140
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Hmm the generator not populating the "hotkey" variable is definitely a bug with the generator itself. But the first code should work, at least in IE. To make this script cross browser compatible, use the below instead:

    Code:
    <script language="JavaScript1.2">
    
    /*
    Home Hot Key Script-
    &#169; Dynamic Drive (www.dynamicdrive.com)
    For full source code, installation instructions,
    100's more DHTML scripts, and Terms Of
    Use, visit dynamicdrive.com
    */
    
    var hotkey=104
    var destination="http://www.dynamicdrive.com"
    if (document.layers)
    document.captureEvents(Event.KEYPRESS)
    function backhome(e){
    if (!document.all){
    if (e.which==hotkey)
    window.location=destination
    }
    else if (document.all){
    if (event.keyCode==hotkey)
    window.location=destination
    }
    }
    document.onkeypress=backhome
    
    </script>
    I'll have to update the generator soon for the bug.

  3. #3
    Join Date
    Oct 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Still having trouble

    Thanks..for the added code. I put it in my page and tried it with no avail. Any suggestions on why its not working? I have it in the <head> like I said. Is there something else that could be making it not work?

  4. #4
    Join Date
    Aug 2004
    Posts
    10,140
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Hmm what browser are you using? Also, did you remember to set focus on the browser window (ie: click anywhere in it) before pressing "h"?

  5. #5
    Join Date
    Oct 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Yeah

    Yeah, I tried that. What's weird is it would originally work with dynamic drives url but when I substituted it with my url it didn't work. Now it doesn't work at all.

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
  •