472,846 Members | 2,434 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,846 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 11909
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
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...

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.