473,806 Members | 2,874 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can't add return false with addEventListene r in Firefox

Hi,

Does anyone know why I can't add return false with addEventListene r 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.u k/intl/en_uk/images/logo.gif"
onmousedown="re turn false">
<img name="myImg2" id="myImg2"
src="http://www.google.co.u k/intl/en_uk/images/logo.gif">
<img name="myImg3" id="myImg3"
src="http://www.google.co.u k/intl/en_uk/images/logo.gif">

<script>
function doOnload(){
document.getEle mentById('myImg 2').addEventLis tener('mousedow n',function(){r eturn
false;},true);
document.getEle mentById('myImg 3').addEventLis tener('mousedow n',function(){a lert('down');}, true);
}

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

Thanks anyone who can help.

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


Because Firefox/Mozilla will ignore any result returned from a function
registered with addEventListene r. 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:

addEventListene r(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.
removeEventList ener(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(e vt)
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 addEventListene r 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.u k/intl/en_uk/images/logo.gif"
onmousedown="re turn false">
<img name="myImg2" id="myImg2"
src="http://www.google.co.u k/intl/en_uk/images/logo.gif">
document.getEle mentById('myImg 2').addEventLis tener('mousedow n',function(){r eturn
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.getEle mentById('myImg 2').addEventLis tener(
'mousedown',
function (evt) {
if (evt.preventDef ault) {
evt.preventDefa ult();
}
},
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
5783
by: Yuk Cheng | last post by:
<<<start index.htm>>> <html> <head> <script> function perform(action){ } </script> </head>
39
6570
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. When it completes, it can call a success, or a failure function. The names of these success, or failure functions will differ, and I'd like to know how I can pass the name of a function to my tool, and how my tool can call the function, using that...
11
43972
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 me a 100% pass with W3C. Any ideas? Thanks.
1
2257
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 duct tape and chicken wire the links that I'm creating follow the hrefs, killing the associated action. To get around this, I'm assigning the URL which I need in the logMe function to a made up attribute, rather than use newlink.href as I do...
4
4851
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 type="text/javascript"> window.onload = function(){ var strCook = document.cookie;
6
2369
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. I think there is a window.addEventListener() function but I am not sure which event to listen to. Thank you.
3
2020
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 offered the chance to delete or edit it. I'm trying to figure out how that is done. It seems like either you can all LI elements to an addEventListener kind of thing, or you do something like this: document.onmouseover= moveDeleteControls;
5
2229
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, etc.). It is used as follows: addElementToPage("writeroot", "input", "type:button, text:testText, value:testvalue, onclick:test1") The first argument is an ID of the location where the new element it to be appended. The second argument is the type...
11
2848
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: Line: 5 Char: 1 Error: 'document' is undefined
0
9597
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
10618
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
10371
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
9187
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...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
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
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
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
3
3008
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.