Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feature Detection for setDragImage of HTML5 Drag and Drop

Is there a way to do feature detection for setDragImage of HTML5 Drag and Drop (in JavaScript or Dart)?

I do the general HTML5 Drag and Drop feature detection with the following (from guide to detecting everything):

return 'draggable' in document.createElement('span');

This will return true for Chrome, Firefox, etc., and IE10. It will return false for IE9.

Now, the problem is with IE10: While it supports most of HTML5 Drag and Drop, setDragImage is not supported and I need to provide a polyfill just for setDragImage. But I couldn't figure out a way how to detect this.

like image 688
Marco Jakob Avatar asked Jun 03 '13 09:06

Marco Jakob


People also ask

What is drag-and-drop feature in HTML5 explain with example?

HTML Drag and Drop (DnD) is a feature of HTML5. It is a powerful user interface concept which is used to copy, reorder and delete items with the help of mouse. You can hold the mouse button down over an element and drag it to another location. If you want to drop the element there, just release the mouse button.

How does HTML5 implement drag-and-drop?

HTML drag-and-drop uses the DOM event model and drag events inherited from mouse events . A typical drag operation begins when a user selects a draggable element, drags the element to a droppable element, and then releases the dragged element.

Does HTML5 support drag-and-drop?

Complete HTML/CSS Course 2022 Now HTML 5 came up with a Drag and Drop (DnD) API that brings native DnD support to the browser making it much easier to code up. HTML 5 DnD is supported by all the major browsers like Chrome, Firefox 3.5 and Safari 4 etc.


1 Answers

This solution assumes general D&D support has already been checked.

JavaScript (tested in IE, Firefox, Opera and Chrome):

function test() {
    var testVar = window.DataTransfer || window.Clipboard;  // Clipboard is for Chrome
    if("setDragImage" in testVar.prototype) {
        window.alert("supported");
    } else {
        window.alert("not supported");
    }
}

Dart:

I didn't find a way to do this with "native" Dart code, so js-interop is the way to go.

like image 118
MarioP Avatar answered Oct 30 '22 10:10

MarioP