<html>

<head>
<title>New Page 11</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<script language="JavaScript1.2">
if (document.layers)
document.captureEvents(Event.KEYPRESS)
function backhome(e){
var targeturl="index.htm"
if (document.layers){
if (e.which==104||e.which==72)
window.location=targeturl
}
else if (document.all){
if (event.keyCode==104||event.keyCode==72)
window.location=targeturl
}
}
document.onkeypress=backhome
</script>
</head>

<body>

<p align="center">Hit The(H) key on your keyboard to send you to a home page that you
configure!!</p>
</body>
</html>

Recommended Answers

All 4 Replies

You can handle the keys pressed on the keyboard:

document.onkeypress = function(e) {
 return HandleKey(e);
}

function HandleKey(event2) {

     var key;  
     
     /* Retrieving the pressed key: */
	 
     if (window.event) {
          key = window.event.keyCode; //IE
     } else {
          key = event2.which; //firefox    
     }
	 
     /* Switching the pressed key: */
	 
     if (key == 97) {
	 
	alert("You pressed the left arrow!");
	return false;
		
     } 
	 
}

You only need to find the keycode of the "H" key.

~G

You only need to find the keycode of the "H" key.

His code already has that.
72 == H
104 == h

Good job you figured that out

Good job you figured that out

You are obviously missing the point

murtazamzk, try:

<script>
function backhome(e){
	var targeturl="index.htm"
	if (document.all)
	{
		if (event.keyCode==104||event.keyCode==72)
			window.location=targeturl
	}
	else
	{
		if (e.which==104||e.which==72)
			window.location=targeturl
	}
}
document.onkeypress=backhome
</script>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.