473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

onKeyPress in Opera 7.11


I have included a file below that tests onKeyPress in Opera 7.11. I am
getting peculiar behavior. When the file is first loaded, pressing the
keypad + causes the textarea to get physically larger on the screen, and
pressing the keypad - causes the textarea to get physically smaller. I
click on the scrollbar then this behaviour stops and subsequent
keystrokes are displayed appropriately. Is this some kind of bug in
Opera 7.11?

================================================== ==========
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 strict//EN">
<html>
<head>
<title>Title</title>
<script type="text/javascript">

var transcriptContents = "";
var lineCnt = 0;

function tprint(_line) {
transcriptContents += lineCnt++ + " "+ _line + "\n";
transcript.value = transcriptContents;
};

function Initialize() {
transcript = document.getElementById("transcriptId");
tprint("Ready...");
};

function OnKeyPress() {
var code;
var codeStr;
var charStr;
code = event.keyCode ?
event.keyCode :
event.charCode ?
event.charCode :
event.which;
codeStr = code.toString();
charStr = Code2Str(code);
tprint(" code:" + codeStr + " char:" + charStr);
return false;
};

function Code2Str(code) {
switch(code) {
case 57357:return '<Home>';break;
case 57358:return '<End>';break;
case 57359:return '<PageUp>';break;
case 57360:return '<PageDown>';break;
case 57361:return '<UpArrow>';break;
case 57362:return '<DownArrow>';break;
case 57363:return '<LeftArrow>';break;
case 57364:return '<RightArrow>';break;
case 57370:return '<Insert>';break;
case 57371:return '<Delete>';break;
case 57376:return '<Alt>';break;
case 57377:return '<Shift>';break;
case 57378:return '<Ctrl>';break;
case 8:return '<Backspace>';break;
case 9:return '<Tab>';break;
case 10:return '<Shift-Tab>';break;
case 13:return '<Enter>';break;
default:return String.fromCharCode(code);
};
};

</script>
</head>
<body onLoad="Initialize()" onKeyPress="OnKeyPress()">
<p>Transcript</p>
<textarea name='transcript'
id='transcriptId'
size=50
wrap="soft"
readonly
rows=22 cols=30 >
</textarea>
</body>
</html>
--
Life is an offensive, directed against the repetitious mechanism of the
Universe.
--Alfred North Whitehead (1861-1947)
Jul 20 '05 #1
5 4162


Albert Wagner wrote:
I have included a file below that tests onKeyPress in Opera 7.11. I am
getting peculiar behavior. When the file is first loaded, pressing the
keypad + causes the textarea to get physically larger on the screen, and
pressing the keypad - causes the textarea to get physically smaller. I
click on the scrollbar then this behaviour stops and subsequent
keystrokes are displayed appropriately. Is this some kind of bug in
Opera 7.11?


If you look at the View->Zoom menu of Opera 7 then you will find that
+/- are indeed mapped to zoom in/out by 10%

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
On Sun, 28 Sep 2003 13:44:01 +0200
Martin Honnen <Ma***********@t-online.de> wrote:


Albert Wagner wrote:
I have included a file below that tests onKeyPress in Opera 7.11. I
am getting peculiar behavior. When the file is first loaded,
pressing the keypad + causes the textarea to get physically larger
on the screen, and pressing the keypad - causes the textarea to get
physically smaller. I click on the scrollbar then this behaviour
stops and subsequent keystrokes are displayed appropriately. Is
this some kind of bug in Opera 7.11?


If you look at the View->Zoom menu of Opera 7 then you will find that
+/- are indeed mapped to zoom in/out by 10%

<snip>

I suspected as much, but I am trapping all keyboard input and not
passing it through. The code traps +/- from the main keyboard but +/-
from the keypad on the right get through, UNTIL the textarea scroll bar
is clicked; then they too are successfully trapped. So, I assume that
you are saying that: "yes, it's a bug in Opera 7.11."
--
Life is an offensive, directed against the repetitious mechanism of the
Universe.
--Alfred North Whitehead (1861-1947)
Jul 20 '05 #3
Albert Wagner <al******@tcac.net> writes:
I suspected as much, but I am trapping all keyboard input and not
passing it through. The code traps +/- from the main keyboard but +/-
from the keypad on the right get through, UNTIL the textarea scroll bar
is clicked; then they too are successfully trapped. So, I assume that
you are saying that: "yes, it's a bug in Opera 7.11."


Actually, clicking anywhere in the text area (giving it focus)
prevents the zooming from working.

Not a bug. It is expected behavior. In Opera, the numeric keyboard
keys "+" and "-" have a default behavior, and you do nothing to
suppress it.

If you call the W3C Events DOM method "event.preventDefault()", then
the problem goes away.

Another solution is to change the call to the function to
onKeyPress="return OnKeyPress(event)"
so you further return the false that OnKeyPress returns. This also
prevents the default behavior.

Btw, your code is based on using a global event variable, which is a
bad idea that comes from IE. You should pass the event as an argument
to the handler function. Then it works in Mozilla too.

Also notice that Opera has changed the keyCodes in O7.20, so that it
matches IE and Mozilla, so some of the codes might need to be changed.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
On 28 Sep 2003 17:42:51 +0200
Lasse Reichstein Nielsen <lr*@hotpop.com> wrote:

<snip>
Thank you, Lasse. When I post, I always hope that you reply. I always
get more than just an answer to a question; I also get the why and how
to improve it. Thanks again.

--
Life is an offensive, directed against the repetitious mechanism of the
Universe.
--Alfred North Whitehead (1861-1947)
Jul 20 '05 #5
On 28 Sep 2003 17:42:51 +0200
Lasse Reichstein Nielsen <lr*@hotpop.com> wrote:
<snip>
Also notice that Opera has changed the keyCodes in O7.20, so that it
matches IE and Mozilla, so some of the codes might need to be changed.


I was wondering about those. What keycodes am I looking at from 7.11?

--
Life is an offensive, directed against the repetitious mechanism of the
Universe.
--Alfred North Whitehead (1861-1947)
Jul 20 '05 #6

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

Similar topics

5
by: Fred Brown | last post by:
Hi, I want to cancel a certain key in JavaScript. To do so, I catch the event in OnKeyPress and cancel the default: <head> .... function f(evt) { var evt = (evt) ? evt : ((window.event) ?...
7
by: Kev | last post by:
I need to make some specific alterations to some JavaScript in webpages in order to comply with government guidelines on accessibility. Apparently, whenever the OnClick event is used, it must be...
2
by: Hasan Ammar | last post by:
Is it possible to set up hotkeys using onkeypress? I know it can be done with the usual alphanumeric keys, but what about function keys? or using ctrl/alt combinations? Does anybody have a...
3
by: addi | last post by:
I'm looking to perform input validation on an HTML input text element; specifically, I'm looking to prevent anything other than numerical characters from being entered. I've got it working just...
11
by: LilAndy23 | last post by:
How can I use the onKeyPress event handler in Firefox? onKeyPress doesn't seem to fire in Firefox.
2
by: ~toki | last post by:
How can i take the control of the key events in Class2 ? This is the code snipped that i'd tried (after try some others): public class Main : System.Windows.Forms.Form { protected virtual...
1
by: Simon Wigzell | last post by:
I'm using a javascript function to interecept all key presses and check for valid character and also check the length of the current string and if it is greater than a sent value, set the focus to...
3
by: Robert Inder | last post by:
I am struggling to catch kestrokes within an Internet Explorer 6 window. My window happens to be displaying three frames, though I suspect a similar problem would arise with a single document. ...
1
by: vega80 | last post by:
Hi. I have a problem with assigning an onkeypress-function to dynamically created input-boxes.I want to put the content of an input-field into a tag-list when the user hits enter. This works...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.