Problem applying return false to a div via addEventListener

P

philjhanna

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,true);
} else if(obj.attachEvent){
obj.attachEvent('on'+eventType,functionReference);
}
}

function doOnload(){

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

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

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

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top