admin管理员组文章数量:1316004
I'm developing an interactive file-uploader in JavaScript and HTML in which I need to access the currently dragging files filename (the one that triggers the dragenter event).
But there's a problem, the events dataTransfer member does not contain any files, and I really need to know the filename before the drop event is thrown. Is it possible?
Thanks in advance.
I'm developing an interactive file-uploader in JavaScript and HTML in which I need to access the currently dragging files filename (the one that triggers the dragenter event).
But there's a problem, the events dataTransfer member does not contain any files, and I really need to know the filename before the drop event is thrown. Is it possible?
Thanks in advance.
Share Improve this question asked Jan 6, 2012 at 18:29 mkromanmkroman 4411 gold badge5 silver badges13 bronze badges 1- 1 This is a bug you should be aware of, also this one – robertc Commented Jan 6, 2012 at 18:45
1 Answer
Reset to default 8I guess you might have to declare a local variable for it....and remember to initialize it when drag start....kill it when drag end...(dragend/drop)
assign it in "DragStart".....(NOTE: in dragstart u can assign any value to dataTransfer by using "event.dataTransfer.setData"....but it is not accessible in DragEnter/DragOver)
because "DragEnter" can not access dataTransfer.getData() due to security reason... it is ONLY accessible in "onDrop" action.....
see links below: //Get Data can not be used here (for cross frame) due to: http://msdn.microsoft./en-us/library/ie/ms536436(v=vs.85).aspx
//use dataTransfer.getData in DragEnter/DragOver doesn't work for Chorme http://code.google./p/chromium/issues/detail?id=50009
//dataTransfer.getData is ONLY accessible in DROP for security reason.... http://code.google./p/chromium/issues/detail?id=2141
OR you can check on the following link...see if it is helpful: http://weblog.bocoup./using-datatransfer-with-jquery-events/
MORE: You can also use localStorage/sessionStorage call, which will save the data into browser cache, localStorage can be used in Cross Window (but same browser), sessionStorage is only accessible of the same session. Just do something like: In your DragStart ->
localStorage.setItem("DraggedFileName",myFileName);
In your DragEnter ->
var myFileName = undefined;
if(localStorage.getItem("DraggedFileName"))
myFileName = localStorage.getItem("DraggedFileName");
In your DropEvent and DragEnd ->
if(localStorage.getItem("DraggedFileName"))
localStorage.removeItem("DraggedFileName"); //Remove after Drop/DragEnd, clear it
Hope it helps....
本文标签: javascriptGetting the filename during the dragenter eventStack Overflow
版权声明:本文标题:javascript - Getting the filename during the dragenter event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741995509a2409961.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论