Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts

    moz - How do you stop drag n drop for images.

    No, I'm not trying to protect my images. It's for a script I'm writing. In IE if you want it so the user can't drag images you just use:

    <img src="file.jpg" onmousemove="return false;">

    ,but what do you do for mozilla? I figured it has something to do with captureEvents(Event.MOUSEMOVE), but I can't get it to work.

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Maybe:

    document.addEventListener('mousemove', function(event) { if (event.target.nodeName.toLowerCase() == 'img') { event.stopPropagation(); return false }, true);

    ?

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Doesn't seem to work. How am I supposed to use it? Like so?:

    <html>
    <head>
    <script>
    document.addEventListener('mousemove', function(event) { if (event.target.nodeName.toLowerCase() == 'img') { event.stopPropagation(); return false }, true);
    </script>
    </head>
    <body>
    <img src="file.jpg" onmousemove="return false;">
    </body>
    </html>

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Try mixing in an "event.preventDefault()" before the return false in the anonymous function.

    If that still doesn't work, Mozilla has a suite of dragging events primarily for use in XUL, and I am unsure of how they are applied to HTML/XHTML.

    "draggesture" seems to be an appropriate one.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I figured it out.

    <img src="file.jpg" onmousedown="return false;">

    Odd, but works.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •