[英]Javascript Drag and Drop event - error catching
是否可以捕獲拖放事件的錯誤?
為了給你更多的上下文,在 Windows 10 上,如果我嘗試刪除一個文件,路徑 + 文件名的長度超過 1000 個字符,刪除不起作用。 文件就消失了。
(如果所述文件路徑 + 文件名少於 1000 個字符,則一切正常)。
DataTransferItem
有 1000 個字符的限制,所以我想通知用戶文件的路徑 + 文件名太長。
我有一個帶有ondrop
事件處理程序的簡單 div
contentDiv.ondragover = uploadDragOver;
contentDiv.ondragenter = uploadDragEnter;
contentDiv.ondragleave = uploadDragLeave;
contentDiv.ondragend = uploadDragEnd;
contentDiv.ondrop = readItems;
...
function readItems(e) {
const items = e.dataTransfer.items;
console.log(items);
}
在花了更多時間調查和尋找解決方案后,我遇到了https://css-tricks.com/snippets/javascript/test-if-dragenterdragover-event-contains-files/這是我的金票!
我在 DnD 代碼中添加了類似的方法。 現在,當我嘗試拖動具有瘋狂路徑長度的文件時,我可以吐出“允許放置”或“不允許放置”類型的消息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.