Solved

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
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 the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

751 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