Solved

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

Posted on 2004-08-28
3
217 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
generate random or sequential numbers using xslt 19 32
carriage return in xslt cell 13 63
From XSL to Word - How add a page break? 5 29
Technology stack suggestions 4 61
Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
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.

920 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

14 Experts available now in Live!

Get 1:1 Help Now