By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 1,852 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

Problem applying return false to a div via addEventListener

P: n/a
Hi

I'm having a problem applying return false to a div via
addEventListener.
I'm adding this so that I can drag (click-hold-move) over an image.
(Its so that I can add zooming to the image)
Adding onmousemove="return false" onmousedown="return false" allows
this to happen but I want to add events with
addEventListener/attachEvent instead.
It works in IE6 but not firefox1.0.6
Below is code demonstrating the problem.
If you can tell me what the problem is or if I'm doing something stupid
i'd be very greatful.
----------

Try clicking and holding then moving (dragging) over these 3 images.

<div id="myDiv0">
No events are added so this will result in a no-access sign
appearing.<br>
<img border="1" height="110" width="276" name="myImg0" id="myImg0"
src="http://www.google.co.uk/intl/en_uk/images/logo.gif">
</div>

<div id="myDiv1" onmousemove="return false" onmousedown="return false">
This has return false on onmousemove and onmousedown so there is no
no-access sign and you can drag over the image.<br>
<img border="1" height="110" width="276" name="myImg1" id="myImg1"
src="http://www.google.co.uk/intl/en_uk/images/logo.gif">
</div>

<div id="myDiv2">
This has the same return false's added except they are done via
addEventListener or attachEvent.<br>
However while you can freely drag over this image in IE6 you can't in
FireFox1.0.6<br>
It seems that the return false is not being added to the event though
if I change return false to an alert these alerts are being added.<br>
<img border="1" height="110" width="276" name="myImg2" id="myImg2"
src="http://www.google.co.uk/intl/en_uk/images/logo.gif">
</div>

<script>

function addEvent(obj,eventType,functionReference){
if(obj.addEventListener){
obj.addEventListener(eventType,functionReference,t rue);
} else if(obj.attachEvent){
obj.attachEvent('on'+eventType,functionReference);
}
}

function doOnload(){

addEvent(document.getElementById('myDiv2'),'moused own',function(){return
false;});

addEvent(document.getElementById('myDiv2'),'mousem ove',function(){return
false;});
/*These two work in IE6 and Firefox so the attachement of events
appears to be working

addEvent(document.getElementById('myDiv2'),'moused own',function(){alert('down');});

addEvent(document.getElementById('myDiv2'),'mousem ove',function(){alert('move');});
*/
}

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

Aug 5 '05 #1
Share this Question
Share on Google+
1 Reply


P: 1
Same problem here. Firefox 1.0.6-something under Gentoo Linux. I've spent hours trying to figure this one out. No luck yet. Maybe we should file a bug report. Anyway, i'm going to check the source code of firefox just in case...
Aug 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.