开发者

Drag & drop into Safari 5 results in unexpected file names

I'm getting strange file names when I drop files into Safari. Sometimes it works, sometimes the weird names appear. I'm using evt.dataTransfer.files to read the dropped files.

How can this be mitigated?

Drag & drop into Safari 5 results in unexpected file names

Drag & drop into Safari 5 results in unexpected file names

开发者_如何学编程

Drag & drop into Safari 5 results in unexpected file names


for anyone else who would like to try this... here is a full page. Just open it in Safari and drop files in to the drop zone.

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style type="text/css">
        #dropbox { border: 1px dashed #ccc; padding: 10px; margin: 10px 0; }
        #dropbox:hover { border: 1px dashed green; }
    </style>
    <script type="text/javascript">
        function noop(evt) {
            evt.stopPropagation();
            evt.preventDefault();
        }
        function drop(evt) {
            evt.stopPropagation();
            evt.preventDefault();

            var div = document.getElementById("files");
            var files = evt.dataTransfer.files;
            for (i = 0; i < files.length; i++) {
                var file = files[i];
                div.innerHTML += i + "=" + file.name + " " + file.size + " " + file.type + "<br/>";
            }
        }
        function addlistener() {
            document.getElementById("dropbox").addEventListener("dragenter", noop, false);
            document.getElementById("dropbox").addEventListener("dragover", noop, false);
            document.getElementById("dropbox").addEventListener("dragexit", noop, false);
            document.getElementById("dropbox").addEventListener("drop", drop, false);
        }
    </script>
</head>
<body onload="addlistener()">
    <div id="dropbox">drop zone</div>
    <div id="files"></div>
</body>
</html>

these are the results i get

0=Chrysanthemum.jpg纽`d崰ၐ7 0 
1=Desert.jpgpg 0 
2=Hydrangeas.jpg 595284 image/jpeg
3=Jellyfish.jpg 0 
4=Koala.jpgȘ 0 
5=Lighthouse.jpg 561276 image/jpeg
6=Penguins.jpg 777835 image/jpeg
7=Tulips.jpg 620888 image/jpeg
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜