473,573 Members | 4,147 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 3019
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
7122
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
14438
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...
5
3109
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
9018
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
11007
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...
3
26743
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...
8
4622
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...
20
2835
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
7789
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
7707
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
8037
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
8215
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
8086
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
5296
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3737
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...
1
2227
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
0
1048
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.