Solved

Creating a key-listener (spacebar) on a page using only web languages

Posted on 2004-08-28
3
216 Views
Last Modified: 2010-04-06
Hello All,

Would it be possible to set up a key-listener on a web page using one or any combination of the following languages only: xml, asp, javascript, html, css? I'm guessing css isnt much help here, but you folks know more than me. I want a javascript function to be called when the user hits the spacebar or clicks on a certain link while viewing a page on my site. Getting the link to work is easy. It's getting the spacebar to do what the clicking does that confuses me. I'm not talking about the accesskey attribute, which, with the help of the alt key, simply sets the focus and does nothing else until enter is hit on the keyboard. One key-press to do the job would be ideal; no alt, ctrl, or enter additions. If this is possible, some examples would be greatly appreciated.
0
Comment
Question by:Grins
  • 2
3 Comments
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 125 total points
ID: 11923408
<html>
<head>
<title> hotkey </title>
<script type="text/javascript">
var key1="32";
var x='';
function handler(e)
{
  if (document.all) {
  var evnt = window.event;
  x=evnt.keyCode;
}
else
x=e.charCode;
if (x==key1) location.href='yourlink.html';
}
if (!document.all){
window.captureEvents(Event.KEYPRESS);
window.onkeypress=handler;
}
else
{
document.onkeypress = handler;
}
</script>
</head>
<body>
This is the body of the page
</body>
</html>


Cd&

0
 
LVL 2

Author Comment

by:Grins
ID: 11928559
Nice, I like! Thank you.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 11930730
Glad I could help.  Thanks for the A. :^)

Cd&
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to dynamically set the form action using jQuery.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now