Join the AMA (Ask Me Anything) with Firefox leadership team to talk about Firefox priorities in 2024. Mark your calendar! Thursday, June 13, 17:00 - 19:00 UTC.

Tìm kiếm hỗ trợ

Tránh các lừa đảo về hỗ trợ. Chúng tôi sẽ không bao giờ yêu cầu bạn gọi hoặc nhắn tin đến số điện thoại hoặc chia sẻ thông tin cá nhân. Vui lòng báo cáo hoạt động đáng ngờ bằng cách sử dụng tùy chọn "Báo cáo lạm dụng".

Learn More

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

  • 2 trả lời
  • 1 gặp vấn đề này
  • 68 lượt xem
  • Trả lời mới nhất được viết bởi 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> ```

Tất cả các câu trả lời (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