function read file if window File window FileReader window FileList wi

 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
function read(file)
{
if (window.File && window.FileReader && window.FileList && window.Blob)
{
var fr = new FileReader();
fr.readAsText(file.files[0]);
fr.onload = function (e)
{
document.getElementById('table').innerHTML = getTable(e.target.result);
};
}
}
function getTable(data)
{
var people = data.split('\r\n\r\n');
var result = '';
for (var i in people)
{
result += getRow(people[i]);
}
return "<table border='1px' align='center' width='80%'>"
+ result + '</table>';
}
function getRow(text)
{
var temp = '';
var row = text.split('\r\n');
for (var j in row)
{
if (j === '1' || j === '2')
{
temp += '<td>' + '<a href="' + row[j] + '">' + row[j] + '</a>' + '</td>';
}
else
{
temp += '<td>' + row[j] + '</td>';
}
}
return '<tr>' + temp + '</tr>';
}