0

I am trying to implement drag and drop feature in my website, but after few hours of trying i came to conclusion that there is a bug in chrome, for example try this example and see for your self.

It seems that dataTransfer property doesn't exist therefore i'm getting undefined error.

Here is my code:

$(document).on("dragover", "#dropFile", function(e){
    e.dataTransfer.setData('text/x-example', 'Foobar'); //error
    return false; 
});

$(document).on("drop", "#dropFile", function(e){
    e.preventDefault();

    console.log(e.dataTransfer); //error
});

P.S this does work in firefox.

1 Answer 1

2

I've just been dabbling with drag-drop lately, and my primary browser is chrome and things work great so far. The method I use to wire up the events is a bit different from yours

  $(".droppable").bind("dragover", function (e)
  {
    // do stuff here
  });
  $(".droppable").bind("drop", function (e)
  {
    // do stuff here
  })
Sign up to request clarification or add additional context in comments.

4 Comments

Please check this fiddle and tell what am i doing wrong here jsfiddle.net/7zpFz/1
hmmmm..... I think its working for me (windows, chrome). Drag over makes the text appear, drop makes the file appear. What are you expecting? What are you seeing?
Well neither text appears nor the file, when i drop the file i simply get redirected to that file page
when you drag over and don't drop, does the text change to "Drag Over"? If so, that means drag/drop is working for you. On the drop event, chrome's default behavior seems to be to redirect the browser to the path on your local drive... so that is happening before you see the affect of the drop event in the browser. I don't know how to stop that default behavior, but i do know that it is possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.