473,386 Members | 1,609 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,386 software developers and data experts.

Firefox error? Workaround?

Hi,

Ran into the problem today - in INPUT field Firefox executes
clean-yp of the content if a user presses Esc, _before_ control goes to
the code via onkeydown - and search showed that it's a known issue:

https://bugzilla.mozilla.org/show_bug.cgi?id=236628

The bug is closed due to the inactivity (I've just written to the
Submiter because apparently I don't have rights to re-Open)

For Internet Explorer there is a solition listed in the FAQ:
http://www.faqts.com/knowledge_base/...d/9008/fid/130

but Firefox... Regular ways do not work:
http://www.experts-exchange.com/Web/..._21064248.html

Any information or workaround?

--
Regards,
Paul
http://RusWin.net
Feb 9 '06 #1
10 2991
Paul Gorodyansky wrote:
Hi,

Ran into the problem today - in INPUT field Firefox executes
clean-yp of the content if a user presses Esc, _before_ control goes to
the code via onkeydown - and search showed that it's a known issue:
There appears to be a bug with Firefox and the keydown event related to
showing alerts:

<URL:https://bugzilla.mozilla.org/show_bug.cgi?id=326484>
But otherwise, the behaviour you describe does not happen for me
(Firefox 1.5). Try this:
<input type="text"
onkeydown="document.getElementById('xx').innerHTML = this.value;">
<div id="xx"
onclick="alert(document.getElementById('text-01').value);"</div>


1. Press 'a', no change to 'xx'.
2. Press 'b', see 'a' in 'xx'.
3. Press 'c', see 'ab' in 'xx'.
4. Pres Esc, see 'abc' in 'xx'.
5. Press Esc again, input is cleared but 'abc' still shown in 'xx'.
6. Press Esc again (3rd time), '' shown in 'xx'.
I was using an alert but discovered the bug above when trying that.

[...]
--
Rob
Feb 9 '06 #2
RobG wrote:
[...]

<input type="text"
onkeydown="document.getElementById('xx').innerHTML = this.value;">


Ooops, crappy cut & paste:

<input type="text" id="text-01"
onkeydown="document.getElementById('xx').innerHTML = this.value;">

--
Rob
Feb 9 '06 #3
Hi,

RobG wrote:

...
4. Pres Esc
5. Press Esc again, input is cleared


It's what I reported - about _input being cleared_, that is a user
looses her/his input... Please see BugZilla entry listed in my 1st
message.

--
Regards,
Paul
http://RusWin.net
Feb 9 '06 #4
Paul Gorodyansky wrote:
Hi,

RobG wrote:
...
4. Pres Esc
5. Press Esc again, input is cleared

It's what I reported - about _input being cleared_, that is a user
looses her/his input... Please see BugZilla entry listed in my 1st
message.


Ah, so what you are saying is that you can't prevent the clearing of the
input using JavaScript.

I thought you meant that the content was cleared before the keydown
event was called so you couldn't see what the value was.

I guess a clunky way might be to detect presses of the escape key, grab
the value then use setTimeout() to write it back into the input
(presumably setTimeout will let the escape action compete before putting
the content back in). Sample below:
<script type="text/javascript">
function isEsc(e)
{
var e = e || window.event;
var kCode = e.keyCode || e.which;
return (kCode && '27' == kCode);
}

function checkKey(e, el)
{
var val = el.value;
var e = e || window.event;
if (isEsc(e)){
setTimeout(function(){el.value=val;},10);
}
}
</script>

<input type="text" onkeydown="checkKey(event, this);">
Lightly tested in Firefox and IE, there may be issues with older
browsers (Some older browsers may not like functions as arguments to
setTimeout).

--
Rob
Feb 9 '06 #5
Hi,

Unfortunately, The Bug filed and another link I provided -
at Experts forum - specify, that Firefox erases the content BEFORE
_any_ Javascript code based on OnKeyDown executes :(

--
Regards,
Paul Gorodyansky
"Cyrillic (Russian): instructions for Windows and Internet":
http://RusWin.net
Feb 9 '06 #6
VK

Paul Gorodyansky wrote:
Hi,

Unfortunately, The Bug filed and another link I provided -
at Experts forum - specify, that Firefox erases the content BEFORE
_any_ Javascript code based on OnKeyDown executes :(


I would screw on textbox and write my own widget using CSS and
contentEditable. A bit of one time hassle but nothing in comparison of
overriding default input behavior, believe me.

Feb 10 '06 #7
Paul Gorodyansky wrote:
Hi,

Unfortunately, The Bug filed and another link I provided -
at Experts forum - specify, that Firefox erases the content BEFORE
_any_ Javascript code based on OnKeyDown executes :(


That's not what seems to happen for me, did you try the code I posted?
As far as I can tell, it works as you require.

--
Rob
Feb 10 '06 #8
Hi,

RobG wrote:

Paul Gorodyansky wrote:
Hi,

Unfortunately, The Bug filed and another link I provided -
at Experts forum - specify, that Firefox erases the content BEFORE
_any_ Javascript code based on OnKeyDown executes :(


That's not what seems to happen for me, did you try the code I posted?
As far as I can tell, it works as you require.


I did not try before - my mistake - because I _knew_ :-) that Firefox
erases the text _before_ the functions linked to OnKeyDown is called,
but I did not pay attention that you _store_ the whole content -
so even if it's erased, you restore it from the variable.

Yes, your code works in _your_ variant - when onkeydown is used
in INPUT control itself. But it does not work in my code -
I have it - forgot for what reason - in a <form
tag and not in the <input tag.
So if I use your code in <form - does not wokr, content is erased -
see below. But may be I should move onkydown check to INPUT field...
Cannot remember why I have it in <form - may be long ago I used
some Web example or so...

Thanks! It's one of the possible work-arounds - using your code.

<html>
<head>
<title>abc</title>
<script type="text/javascript">
function isEsc(e)
{
var e = e || window.event;
var kCode = e.keyCode || e.which;
return (kCode && '27' == kCode);
}

function checkKey(e, el)
{
var val = el.value;
var e = e || window.event;
if (isEsc(e)){
setTimeout(function(){el.value=val;},10);
}
}
</script>
</head>
<body>
<form name = "my" onkeydown="checkKey(event, this);">
<INPUT TYPE="text" NAME="Subject" SIZE="45" MAXLENGTH="60">
</form>
</body>
</html>


--
Regards,
Paul
Feb 10 '06 #9
Paul Gorodyansky wrote:
Hi,

RobG wrote:
Paul Gorodyansky wrote:
Hi,

Unfortunately, The Bug filed and another link I provided -
at Experts forum - specify, that Firefox erases the content BEFORE
_any_ Javascript code based on OnKeyDown executes :(


That's not what seems to happen for me, did you try the code I posted?
As far as I can tell, it works as you require.

I did not try before - my mistake - because I _knew_ :-) that Firefox
erases the text _before_ the functions linked to OnKeyDown is called,
but I did not pay attention that you _store_ the whole content -
so even if it's erased, you restore it from the variable.

Yes, your code works in _your_ variant - when onkeydown is used
in INPUT control itself. But it does not work in my code -
I have it - forgot for what reason - in a <form
tag and not in the <input tag.


I presume you did that so you only need to put one handler on the form
and also because in IE a double-escape clears the entire form, not just
the input that has focus (as in Firefox).

This gave me a brainstorm: for Gecko browsers use addEventListener and
stopPropagation in the capture phase. After trial and error to discover
that it doesn't work, I found that quirksmode also says that you can't
cancel the capture phase of an event, only the bubbling phase.

<URL:http://www.quirksmode.org/js/events_order.html>
I wonder why it's not possible for stopPropagation to take a single
boolean argument to determine whether to stop events on the capture or
bubble phases, just like addEventListener does to determine whether to
fire events on capture or bubble? The default could be on bubble
(false) for backward compatibility.

There is a stopImmediatePropagation in DOM 3, but it doesn't seem to be
implemented yet in Firefox:

<URL:http://www.w3.org/TR/DOM-Level-3-Events/events.html#Events-Event-stopImmediatePropagation>
Anyhow, figured the 'best' way is to add a single event handler to the
form. If addEventListener supported (Gecko /et al/), the setTimeout()
hack is added, if attachEvent supported (IE, others?) a simple 'return
false if escape is pressed' function is added.

The saving is that you can use script to put the handler on the handler
on the form and fire on the capture phase for Gecko browsers *before*
input is cleared, so you can effectively disable the Esc key for text
inputs in script-enabled browsers - sample below (lightly tested in
Firefox 1.5 and IE 6 only):
<script type="text/javascript">

function addEvt(elID, funcRef)
{
var el;
if ( !document.getElementById
|| !(el = document.getElementById(elID)) ){
return;
}

if (el.addEventListener){

// For Gecko, use the setTimeout hack
el.addEventListener('keydown', stopEsc, true);
} else if (el.attachEvent){

// For IE, just return false if Esc pressed
el.attachEvent('onkeydown', function(){
return !isEsc();
});
}
}

function isEsc(e)
{
var e = e || window.event;
var kCode = e.keyCode || e.which;
return kCode && '27' == kCode;
}

function stopEsc(e)
{
var e = e || window.event;
var tgt = e.target || e.srcElement;
var val;
if ('input' == tgt.nodeName.toLowerCase()
&& 'text' == tgt.type
&& (val = tgt.value)){
if (isEsc(e)){
setTimeout(function(){tgt.value=val;},10);
return false;
}
}
}

window.onload = function() {
addEvt('formA', stopEsc);
}

</script>

<form name="formA" id="formA" action="">
<div>
<!-- Dummy inputs for test -->
<input type="text">
<input type="text">
<input type="checkbox" name="cb-01">
<input type="checkbox" name="cb-02">
</div>
</form>
--
Rob
Feb 10 '06 #10
Thanks, Rob,

it looks like a complete solution!
The only thing - productivity-wise - we store entire typed text each
time _any_ key is pressed... But it's probably not noticable,

This <INPUT situation arised only couple days ago - before that
I used my code only with <TEXTAREA - where Firefox does not have
such issue with Esc and IE could be ESC-safe in a regular way - as in
your example code.

It's good that the work-around has been found for <INPUT case!
Thanks,
Paul
Feb 10 '06 #11

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

Similar topics

2
by: David | last post by:
Greetings, Does anyone know of a workaround for the onresize bug in Firefox? <body onresize="history.go(0)"> I've looked all around and can't seem to find a working workaround. David
6
by: Mark Olbert | last post by:
The doPostBack javascript functioning is not submitting the page when called by linkbuttons (or an autopostback checkbox, for that matter). I'm aware of a problem with Netscape browsers and the...
5
by: SPE - Stani's Python Editor | last post by:
Hi, During optimizing SPE for Ubuntu, I found something strange. I have Ubuntu 5.10 "The Breezy Badger" and unfortunately this code is not working: >>> import webbrowser >>>...
4
by: Angel | last post by:
Hello Everybody, I have the following lines in my code 1) totalElements=eval("document."+formname+".RCBillingCycle"+totalRCRows+".length") 2) var newoption=new Option...
2
by: Noah Sussman | last post by:
Hello, I am writing a function to reposition an element based on whether one of its edges is outside the visible area of the browser window (the code is below). My client has asked for code...
3
by: jon | last post by:
Hello, I've had long standing code that runs in IE, that I'm testing with firefox unsuccessfully now. The problem seems to be that images that I dynamically create don't fire their onload event...
8
by: Dustan | last post by:
At http://docs.python.org/whatsnew/modules.html on the webbrowser module, it says "A number of additional browsers were added to the supported list such as Firefox, Opera, Konqueror, and elinks." ...
20
by: Hush | last post by:
Hi, The following code works fine in IE7 but FF returns with an error: Access denied to achieve the property Element.firstChild. In this line: nodes = xmlDoc.documentElement.childNodes; My...
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:
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
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,...
0
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...

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.