Thursday, May 10, 2012

Drag & Drop on Safari iOS: Wont drag, wont respond to drop on desktop/iPad


I am coding a webpage to be viewed on iPad. It uses Safaris/Webkits drag & drop. I have exactly copied Safari's example drag & drop code but it wont work.



My Problem: The ondrop event is never triggered when I run the webpage(HTML, CSS & Javascript) on Safari Desktop or on Safari on an iPad. On ipad I cannot even drag the elements(the microscope thingie appears & it wont drag when I hold & move my finger over the element). The drag does work on desktop though.



Whats going wrong?



The small code example can be found at the very bottom of this page: http://developer.apple.com/library/safari/#documentation/appleapplications/Conceptual/SafariJSProgTopics/Tasks/DragAndDrop.html



Here is the JSFiddle (remember the drag & drop is Webkit so only for Safari-this webpage is for ipad only): http://jsfiddle.net/eyM3y/


Source: Tips4all

2 comments:

  1. Working alternative :

    Firstly, use jquery UI http://jqueryui.com/demos/ for drag and drop functionality

    and then add this script https://github.com/furf/jquery-ui-touch-punch for playing it in Ipad or Iphone.

    Hope it helps.

    ReplyDelete
  2. Did you read the top of the page you linked to in Apple's documentation? It says:


    Note: This technology is supported only on desktop versions of Safari. For iOS, use DOM Touch, described in Handling Events (part of Safari Web Content Guide) and Safari DOM Additions Reference.


    DOM Touch link

    Safari DOM Additions link

    I believe you may want to listen for the touchmove and touchend events instead of on drag and on drop. :)

    ReplyDelete