...

View Full Version : moz - How do you stop drag n drop for images.



x_goose_x
08-08-2002, 04:06 AM
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.

jkd
08-08-2002, 04:21 AM
Maybe:

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

?

x_goose_x
08-08-2002, 04:33 AM
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>

jkd
08-08-2002, 04:38 AM
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.

x_goose_x
08-08-2002, 04:56 AM
I figured it out.

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

Odd, but works.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum