PDA

View Full Version : Having trouble with Hot Key script



cz231
10-10-2006, 10:11 PM
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

ddadmin
10-11-2006, 10:52 AM
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:


<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.

cz231
10-11-2006, 08:51 PM
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?

ddadmin
10-12-2006, 11:14 AM
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"?

cz231
10-15-2006, 05:07 PM
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.