Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-25-2008, 11:37 PM   PM User | #1
Skotty
New Coder

 
Join Date: Aug 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Skotty is an unknown quantity at this point
Drag Drop Problems in Firefox

Has anyone encountered a problem in Firefox when using drag and drop script where when attempting to drag, the icon changes to a circle with a slash through it?

I'm using a custom drag and drop script. In my initial demo pages, it works fine in both IE and Firefox. But when I integrated it into a JSF application, Firefox started having problems (it still worked fine in IE).

Essentially what happen is events stop firing until the mouse button is released, at which point one final onmousemove is fired but the onmouseup is not. It's almost as if Firefox thinks it can't fire off the onmousemove events fast enough and decides to just give up until the drag is over. However, once the drag is over, since the onmouseup doesn't fire, it continues to behave as if you were dragging, at which point the dragged item can be dragged around the screen with no problems.

Has anyone encountered this or something similar before? Did you figure out what the problem was? Did you find a solution?

I would include an example, but the examples (at least so far) always work. Seems the page has to get complicated before the problem surfaces.

Thanks.

Last edited by Skotty; 08-26-2008 at 03:29 PM..
Skotty is offline   Reply With Quote
Old 08-26-2008, 02:50 PM   PM User | #2
Skotty
New Coder

 
Join Date: Aug 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Skotty is an unknown quantity at this point
I traced the code to see what the last line of script executed is before it stops working. Interestingly, I found that the move operation is fully completed each time.

A little more detail on the behavior -- it doesn't stop working right away, each time the drag works for about 4 or 5 pixels before it stops working. And I was wrong before when I said it fires the onmousemove 1 last time when the mouse button is released...it actually fires the onmousemove 2 times when the mouse button is released.

I'm wondering if maybe there is some other script on the page that would cause this problem. Maybe another script that is trying to buffer information or something, causing out of memory situation or something. Anyone have any ideas?
Skotty is offline   Reply With Quote
Old 08-26-2008, 02:56 PM   PM User | #3
Skotty
New Coder

 
Join Date: Aug 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Skotty is an unknown quantity at this point
I just now came to the following realization -- the drag handles are currently images. Firefox has behavior where it allows you to drag images off to other windows, or on to the desktop. This is likely interfering with the drag operation. I'm pretty sure this is the problem. Now to look for a solution.
Skotty is offline   Reply With Quote
Old 08-26-2008, 03:11 PM   PM User | #4
Skotty
New Coder

 
Join Date: Aug 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Skotty is an unknown quantity at this point
Yay! I just solved the problem.

The solution in Firefox (at least in my case) is to call event.preventDefault() in the onmousedown event handler.

Code:
function handleMouseDown(event) {
	event.preventDefault();
	...
}
A second solution is to return false from the onmousedown event handler. This also works.

Code:
function handleMouseDown(event) {
	...
	return false;
}

<sometag ... onmousedown="return handleMouseDown(event)"/>
I still don't know the exact scenario that causes the problem since it's not always needed...probably the element nesting plays a part.

Hopefully this thread helps someone else someday.

Last edited by Skotty; 08-26-2008 at 03:22 PM.. Reason: Added second solution
Skotty is offline   Reply With Quote
Old 09-02-2008, 06:05 PM   PM User | #5
terminon
New to the CF scene

 
Join Date: Sep 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
terminon is an unknown quantity at this point
Thumbs up Thanks!

I've been trying to figure out how to get around the image drag-drop behavior for a while now. I had tried return false, but for some reason it wasn't working (perhaps it is because of the way I am chaining functions together on mousedown, etc) -- anyway, preventDefault() does the trick beautifully. Thanks!
terminon is offline   Reply With Quote
Old 10-01-2008, 02:18 AM   PM User | #6
Maulkye
New to the CF scene

 
Join Date: Oct 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Maulkye is an unknown quantity at this point
Question Yes but...

I had a similar problem and a similar solution works, but what if you need that event to propagate up to multiple containers for the initial event recipient? I don't want to have to terminate the entire chain of "mousedown" events just to stop this behavior.

I guess I can fire it manually after I intercept the event, but I'll have to handle that outside of normal protocol.

Is there a better way? Surely the bright folks over at FF central thought about this beforehand and have exposed a method, yet unknown to myself, that will disable this?

Thanks,
Maulkye
Maulkye is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:18 AM.


Advertisement
Log in to turn off these ads.