Windows 10 will reach EOS (end of support) on October 14, 2025. For more information, see this article.

Pomoc přepytać

Hladajće so wobšudstwa pomocy. Njenamołwimy was ženje, telefonowe čisło zawołać, SMS pósłać abo wosobinske informacije přeradźić. Prošu zdźělće podhladnu aktiwitu z pomocu nastajenja „Znjewužiwanje zdźělić“.

Dalše informacije

BUG Drag-dropping inside a document fails with Uncaught DOMException: The operation is insecure

  • 2 wotmołwje
  • 1 ma tutón problem
  • 20 napohladow
  • Poslednja wotmołwa wot zeroknight

more options

When I start to drag a div to drop it in another div on the same page, it fails with the message:

"Uncaught DOMException: The operation is insecure.

   dragstart_handler http://127.0.0.1:5000/main.js:7"

This is main.js:

``` function dragstart_handler(event) {

   var t = event.target;
   while (! t.draggable == "true" && t.tagName != "BODY") {
       t = t.parentNode;
   };
   if (! t.draggable) return;
   event.dataTransfer.setData("application/x-moz-node", t);

... ```

All dragging goes inside the same document, so "The operation is insecure" shouldn't happen.

Also I get an empty string when trying to get the draggable data:

``` function drop_handler(event) {

   var t = event.target;
   const parent = t.parentNode;
   if (parent.id == "drag_area") {
       event.preventDefault();
       const data = event.dataTransfer.getData("application/x-moz-node");

Here's how I assign draggables and drop areas:

``` window.addEventListener("DOMContentLoaded", () => {

   const dragArea = document.getElementById("drag_area");
   dragArea.addEventListener("dragstart", dragstart_handler);
   dragArea.addEventListener("dragover", dragover_handler);
   dragArea.addEventListener("dragleave", dragleave_handler);
   dragArea.addEventListener("drop", drop_handler);

}); ```

HTML:

```

Drag this

```

When I start to drag a div to drop it in another div on the same page, it fails with the message: "Uncaught DOMException: The operation is insecure. dragstart_handler http://127.0.0.1:5000/main.js:7" This is main.js: ``` function dragstart_handler(event) { var t = event.target; while (! t.draggable == "true" && t.tagName != "BODY") { t = t.parentNode; }; if (! t.draggable) return; event.dataTransfer.setData("application/x-moz-node", t); ... ``` All dragging goes inside the same document, so "The operation is insecure" shouldn't happen. Also I get an empty string when trying to get the draggable data: ``` function drop_handler(event) { var t = event.target; const parent = t.parentNode; if (parent.id == "drag_area") { event.preventDefault(); const data = event.dataTransfer.getData("application/x-moz-node"); Here's how I assign draggables and drop areas: ``` window.addEventListener("DOMContentLoaded", () => { const dragArea = document.getElementById("drag_area"); dragArea.addEventListener("dragstart", dragstart_handler); dragArea.addEventListener("dragover", dragover_handler); dragArea.addEventListener("dragleave", dragleave_handler); dragArea.addEventListener("drop", drop_handler); }); ``` HTML: ``` <div id="drag_area"> <div class="list"> <div draggable="true">Drag this</div> </div> <div class="list"> </div> </div> ```

Wšě wotmołwy (2)

more options

PS. I see there is an issue on GitHub

https://github.com/mdn/content/issues/22929

and it's closed, but there is no solution???

Dragging HTML elements on page is a pretty important feature. How comes the bug so major remains unsolved for years?

more options

The documentation is outdated, "application/x-moz-node" does not exist and would be non-standard anyway. The data transfer only needs to identify the element, this can be done with type "text/plain" and then you can append it to the drop zone.

Refer to this example: https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/setData