473,915 Members | 3,834 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3066
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.mozill a.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="docu ment.getElement ById('xx').inne rHTML = this.value;">
<div id="xx"
onclick="alert( document.getEle mentById('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="docu ment.getElement ById('xx').inne rHTML = this.value;">


Ooops, crappy cut & paste:

<input type="text" id="text-01"
onkeydown="docu ment.getElement ById('xx').inne rHTML = 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(func tion(){el.value =val;},10);
}
}
</script>

<input type="text" onkeydown="chec kKey(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(func tion(){el.value =val;},10);
}
}
</script>
</head>
<body>
<form name = "my" onkeydown="chec kKey(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,

Unfortunatel y, 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 addEventListene r 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.ht ml>
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 addEventListene r does to determine whether to
fire events on capture or bubble? The default could be on bubble
(false) for backward compatibility.

There is a stopImmediatePr opagation 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#Eve nts-Event-stopImmediatePr opagation>
Anyhow, figured the 'best' way is to add a single event handler to the
form. If addEventListene r 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.getEl ementById
|| !(el = document.getEle mentById(elID)) ){
return;
}

if (el.addEventLis tener){

// For Gecko, use the setTimeout hack
el.addEventList ener('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.to LowerCase()
&& 'text' == tgt.type
&& (val = tgt.value)){
if (isEsc(e)){
setTimeout(func tion(){tgt.valu e=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

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

Similar topics

2
7142
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
14476
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 postback code, but I have a workaround for that installed (and it looks like the code generated by ASP.NET when it renders the page does the same thing, namely, setting document<). However, the problem still exists under firefox. Has anyone come...
5
3126
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 >>> webbrowser.open("http://www.python.org") It does not throw an exception, but is not able to launch a browser.
4
9041
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 (BillingCycleName,BillingCycleId); eval("document."+formname+".RCBillingCycle"+totalRCRows+".options= newoption");
2
11115
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 that runs in IE6 and Firefox. However, I am having a problem in Firefox. I've recently discovered that Firefox considers the clientWidth and clientHeight of hidden elements to be "0". I am getting this result on elements with the CSS property...
3
26771
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 in firefox. The onload method I assign is never being called. Any ideas why firefox isn't calling this, or what I can do for a workaround? Below is approxiatemate code of what I'm doing...
8
4641
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." I just installed python 2.5, looking forward to being able to control firefox without having to make it my default browser, but... I don't seem to have that functionality. In IDLE: {'windows-default': }
20
2896
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 code:
0
9883
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11359
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10543
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9734
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5944
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4779
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
2
4346
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.