-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileAPIExample05.htm
executable file
·48 lines (38 loc) · 1.64 KB
/
FileAPIExample05.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html>
<head>
<title>File API Example</title>
<script src="EventUtil.js"></script>
</head>
<body>
<p>This page is a demonstration of the File API with Drag and Drop. This works in the latest versions of all major browsers, but you may need to place this file on a web server to get it to work.</p>
<div id="droptarget" style="width: 500px; height: 200px; background: silver">
Drop some files here
</div>
<script>
window.onload = function(){
var droptarget = document.getElementById("droptarget");
function handleEvent(event){
var info = "",
output = document.getElementById("output"),
files, i, len;
EventUtil.preventDefault(event);
if (event.type == "drop"){
files = event.dataTransfer.files;
i = 0;
len = files.length;
while (i < len){
info += files[i].name + " (" + files[i].type + ", " + files[i].size + " bytes)<br>";
i++;
}
output.innerHTML = info;
}
}
EventUtil.addHandler(droptarget, "dragenter", handleEvent);
EventUtil.addHandler(droptarget, "dragover", handleEvent);
EventUtil.addHandler(droptarget, "drop", handleEvent);
};
</script>
<pre id="output"></pre>
</body>
</html>