forked from skjApp/HTML5-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrag&DropFile.htm
55 lines (38 loc) · 1.13 KB
/
Drag&DropFile.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
49
50
51
52
53
54
55
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
#div1
{
width:350px;
height:200px;
border:1px solid #aaaaaa;
}
</style>
<script type="text/javascript">
function allowDrop(event)
{
event.preventDefault(); // Cancel the default browser action. This is to ensure that if we drop a link, the browser doesn’t go off and surf to that location
}
function drop(event)
{
event.preventDefault(); // Cancel the default browser action. This is to ensure that if we drop a link, the browser doesn’t go off and surf to that location
var img1 = new Image() ; // variable for holding dropped image's data
var file = event.dataTransfer.files[0] ;
var reader = new FileReader() ;
reader.readAsDataURL(file);
reader.onload = loaded ;
function loaded(evt)
{
img1.src = evt.target.result ;
}
event.target.appendChild(img1);
}
</script>
</head>
<body>
<p>Drag image file from desktop into the rectangle:</p>
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)">
</div>
</body>
</html>