Problem applying return false to a div via addEventListener

Discussion in 'Javascript' started by philjhanna, Aug 5, 2005.

  1. philjhanna

    philjhanna Guest

    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>
     
    philjhanna, Aug 5, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. w i l l
    Replies:
    4
    Views:
    241
    Dan Brussee
    Jul 4, 2003
  2. philjhanna
    Replies:
    1
    Views:
    104
    Martin Honnen
    Aug 9, 2005
  3. Replies:
    1
    Views:
    439
    Randy Webb
    Oct 6, 2005
  4. Replies:
    10
    Views:
    312
    Thomas 'PointedEars' Lahn
    Feb 16, 2006
  5. William Wallace
    Replies:
    25
    Views:
    984
    David Mark
    Aug 14, 2010
Loading...

Share This Page