473,386 Members | 1,785 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.

Can't add return false with addEventListener in Firefox

Hi,

Does anyone know why I can't add return false with addEventListener in
firefox (1.0.6).
This demonstrates the problem
If return false is added to onmousedown then you can drag over the
image which you can do to myImg1 but not myImg2.
myImg3 just shows that the code should work as an alert is added to
this one.

<img name="myImg1" id="myImg1"
src="http://www.google.co.uk/intl/en_uk/images/logo.gif"
onmousedown="return false">
<img name="myImg2" id="myImg2"
src="http://www.google.co.uk/intl/en_uk/images/logo.gif">
<img name="myImg3" id="myImg3"
src="http://www.google.co.uk/intl/en_uk/images/logo.gif">

<script>
function doOnload(){
document.getElementById('myImg2').addEventListener ('mousedown',function(){return
false;},true);
document.getElementById('myImg3').addEventListener ('mousedown',function(){alert('down');},true);
}

window.addEventListener('load',doOnload,true);
</script>

Thanks anyone who can help.

Aug 8 '05 #1
2 11957
philjhanna wrote:
Does anyone know why I can't add return false with addEventListener in
firefox (1.0.6).


Because Firefox/Mozilla will ignore any result returned from a function
registered with addEventListener. If you read the DOM specification for
the EventListener interface you will see that it says there is 'no return value'.

See the following references:

http://www.mozilla.org/docs/dom/domr..._el_ref31.html
http://www.w3.org/TR/2000/REC-DOM-Le...-EventListener

or more specifically
(at http://www.w3.org/TR/2000/REC-DOM-Le...binding.html):

Object EventTarget

The EventTarget object has the following methods:

addEventListener(type, listener, useCapture)
This method has no return value.
The type parameter is of type String.
The listener parameter is a EventListener object.
The useCapture parameter is of type Boolean.
removeEventListener(type, listener, useCapture)
This method has no return value.
The type parameter is of type String.
The listener parameter is a EventListener object.
The useCapture parameter is of type Boolean.
dispatchEvent(evt)
This method returns a Boolean.
The evt parameter is a Event object.
This method can raise a EventException object.

Object EventListener
This is an ECMAScript function reference. This method has no return value.
The parameter is a Event object.

Aug 9 '05 #2


philjhanna wrote:

Does anyone know why I can't add return false with addEventListener in
firefox (1.0.6).
This demonstrates the problem
If return false is added to onmousedown then you can drag over the
image which you can do to myImg1 but not myImg2. <img name="myImg1" id="myImg1"
src="http://www.google.co.uk/intl/en_uk/images/logo.gif"
onmousedown="return false">
<img name="myImg2" id="myImg2"
src="http://www.google.co.uk/intl/en_uk/images/logo.gif">
document.getElementById('myImg2').addEventListener ('mousedown',function(){return
false;},true);


The proper way in the W3C DOM Level 2 Events model to cancel the default
action associated with an event is to call the method preventDefault on
the event object so you should code
document.getElementById('myImg2').addEventListener (
'mousedown',
function (evt) {
if (evt.preventDefault) {
evt.preventDefault();
}
},
false
);
if you want to have that event listener cancel/prevent the default action.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 9 '05 #3

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

Similar topics

4
by: Yuk Cheng | last post by:
<<<start index.htm>>> <html> <head> <script> function perform(action){ } </script> </head>
39
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
11
by: me | last post by:
I have got all my pages to comply with the W3C validator, except this one line as below. I need to keep the line (or the functionalilty) but it would be nice to implement it in a way that gives...
1
by: james.kingston | last post by:
I've read that one must return false from an onclick handler attached to an anchor if we wanted to prevent the browser from following the href. In a greasemonkey script I'm hacking together with...
4
by: Ross | last post by:
I have been using the following script to return a scrollbar to the position it was in before the data was posted. It works in ie but not in firefox. Thanks, R. <script...
6
by: sylcheung | last post by:
Hi, How can I be notified when the document load is complet in JavaScript? I am referring to the whold document load is complete, mean all images/external files/frame/iframes have been loaded. ...
3
by: Jake Barnes | last post by:
37 Signals has built some awesome software with some features I wish I knew how to imitate. When I'm logged into my page (http://lkrubner.backpackit.com/pub/337271) any item that I mouseOver I'm...
5
by: dwmartin18 | last post by:
Hello everyone. I have quite the puzzling problem with a script I have been working on lately. I have created a function that can be called to create a new html element (e.g. input, select, div,...
11
by: LayneMitch via WebmasterKB.com | last post by:
Hello. This is a reference file from a book I read in which the core subject is the use of 'event listeners'. I'm trying to load the file in Firefox and it's giving me an error message: ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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.