Solved

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

Posted on 2004-08-28
3
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

617 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