Solved

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

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

776 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