473,569 Members | 2,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onkeydown

I am trying to figure out what values are returned when keys are
pressed in Mozilla & IE. Here's the code I'm using. There are no
alerts in either browser. Any clues would be greatly appreciated.
Thanks. KK

<html>
<head><title>Re ading Keystrokes</title>

<script language="JavaS cript">
window.onkeyDow n = keyHit;
function keyHit(evt) {
if (evt && evt.which) { //NS
thisKey = evt.which;
}
else if(window.event && window.event.ke yCode) { //IE
thisKey=window. event.keyCode;
}
alert(thisKey)
}
</script>
</head><body></body></html>
Jul 23 '05 #1
4 9988
The method I used to get your script to work is this. First I put the
'onKeyDown' handler in the <body> tag. Second inside the keyHit() function
I made the first line--

var evt = window.event;

--the code works in this format in IE, though I don't know about any cross
browser application.

Do you know anything about how to disable the Backspace Key from
performing the history.back method? I can disable it for text but not for
browsing.

Jul 23 '05 #2
KublaiKhan wrote:
I am trying to figure out what values are returned when keys are
pressed in Mozilla & IE. Here's the code I'm using. There are no
alerts in either browser. Any clues would be greatly appreciated.
Thanks. KK

<html>
<head><title>Re ading Keystrokes</title>

<script language="JavaS cript">
<script type="text/javascript">
window.onkeyDow n = keyHit;
document.onkeyd own = keyHit;
function keyHit(evt) {
if (evt && evt.which) { //NS
thisKey = evt.which;
}
else if(window.event && window.event.ke yCode) { //IE
thisKey=window. event.keyCode;
}
alert(thisKey)
}
function keyHit(evt) {
evt = evt || window.event;
alert(evt.which ? evt.which : evt.keyCode);
}
</script>
</head><body></body></html>


--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq

Jul 23 '05 #3

"KublaiKhan " <bi*****@hotmai l.com> wrote in message
news:f0******** *************** ***@posting.goo gle.com...
I am trying to figure out what values are returned when keys are
pressed in Mozilla & IE. Here's the code I'm using. There are no
alerts in either browser. Any clues would be greatly appreciated.
Thanks. KK

<html>
<head><title>Re ading Keystrokes</title>

<script language="JavaS cript">
<script type="text/javascript">
window.onkeyDow n = keyHit;
document.onkeyd own = keyHit;
if you just want general keyboard response use the
onkeypress handler. It handles upper/lower case
numbers and punctuation. Onkeydown requires a solid
understanding of handling key events.
function keyHit(evt) { if (evt && evt.which) { //NS
// you haven't declared thisKey and it will
// be available as a global variable to the rest of
// your script/s !!
var thisKey; // now local variable
thisKey = evt.which; }
else if(window.event && window.event.ke yCode) { //IE
thisKey=window. event.keyCode;
}
alert(thisKey)
}
</script>
</head><body></body></html>


<script type="text/javascript">
document.onkeyp ress = keyHit;

function keyHit(evt) {
var e = evt || window.event;
var thisKey = e.which || e.keyCode;
alert(String.fr omCharCode(this Key));
}
</script>
HTH
Jimbo
Jul 23 '05 #4
"koethler" <ko******@telus .net> wrote in message news:<45******* *************** ********@localh ost.talkaboutpr ogramming.com>. ..
The method I used to get your script to work is this. First I put the
'onKeyDown' handler in the <body> tag. Second inside the keyHit() function
I made the first line--

var evt = window.event;

--the code works in this format in IE, though I don't know about any cross
browser application.

Do you know anything about how to disable the Backspace Key from
performing the history.back method? I can disable it for text but not for
browsing.


I simplified the code on Grant Wagner's advice to:
<html>
<head><title>Re ading Keystrokes</title>

<script type="text/javascript">
document.onkeyd own = keyHit;
function keyHit(evt) {
evt = evt || window.event;
alert(evt.which ? evt.which : evt.keyCode);
}
</script>
</head><body></body></html>

Turns out my original problem was I had document.onkeyD own instead of
document.onkeyd own (lowercase). Now it works fine under Mozilla & IE6.
Thanks folks. I am very new js. With that in mind, I have pages
1,2,3,4. Link on p. 1 takes you p. 2 which checks for cookies & if
false, does a
this.location.h ref="page3.html "
P. 3 first line is
<meta http-equiv=refresh content="0;url= page4.html">
A link in page 4 then takes you to p. 2. Backward navigation from p.2
now takes you to p.1 with pages 3 & 4 erased from history.
Something to think about.

KK
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3900
by: Z | last post by:
I have sub-classed the TextBox. In its OnKeyDown event I can intercept key strokes, examine them, etc. When I get a certain keycode (e.g., 'A') I want to change it to another unicode key from a different code page (e.g., "\u2801"). But the KeyCode, KeyData, and KeyValue properties of KeyEventArgs are all only getters. They are read only and...
3
7388
by: euler | last post by:
why did the keydown event not fire in this simple example? <HTML> <HEAD><title>keydown_div</title> <script type="text/javascript"> function keydown() { alert("keydown"); } </script>
10
9150
by: b.dam | last post by:
I'm trying the following: function grid() { this._el = document.createElement("TABLE"); var self = this; document.addEventListener("onkeydown", function(event) {self.gridKeyDown(event);}, false); }
2
5929
by: Iver Erling Årva | last post by:
I have come across a problem with the onKeyDown event in some of my forms. I'm using onKeyDown in <form> as a standard method to open my help screen system throughout my system, but I have discovered that If I have a <div></div> section somewhere and then load the contents of it from another file using innerHTML after the main window is...
5
3786
by: Roger Withnell | last post by:
I'm using the following code to start a function on key down. document.onkeydown = OnKeyDown; function OnKeyDown() { vKeyCode = event.keyCode; ..code... }
0
1130
by: =?Utf-8?B?Q0dX?= | last post by:
I have a .NET 1.1 application which uses several grids of text boxs (in repeaters and datagrids) for entering arrays of time values. I use onkeydown to allow users to navigate through the grids using arrow keys. I'm attempting to upgrade to .NET 2.0, but that particular functionality appears to be broken now. The actual javascript function...
0
1177
by: CGW | last post by:
I posted this in a .NET general newsgroup, but then found this group and I think it would be more appropriately posted here. Even though the problem is partially with client side behavior, I'm attempting to deal with it in my VB code behind. Here's my post... I have a .NET 1.1 application which uses several grids of text boxs (in repeaters...
1
5739
eboyjr14
by: eboyjr14 | last post by:
I have this UserScript for Grease monkey. but I can't get the onleydown event to fire in FIREFOX only. I've looked everywhere! // ==UserScript== // @name iGoogle Suggest // @namespace Devin Samarin // @description This automatcally selects the top result for your query. // @include *google.com/ig* //...
8
4257
by: Tony Johansson | last post by:
Hello! I wonder can somebody explain when is it suitable to use these methods OnKeyUp, OnKeyDown and OnKeyPress because these raise an event. These are located in class UserControl. If these raise an event how do I create an handler to catch these raised events. //Tony
0
7701
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8130
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.