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?
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?
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.
Sorry, here it is.
http://www.dynamicdrive.com/dynamicindex5/button1.htm
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>
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>
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?Originally Posted by jscheuer1
Mike
Good point Mike, I thought this was a somewhat silly script to begin with but, it is what the OP asked for.Originally Posted by mwinter
Thanks for your help
Bookmarks