저는 웹에서 여러 가지 옵션을 살펴보고 텍스트 파일을로드하는 방법뿐 아니라 복제하는 방법을 여러 차례 살펴 보았습니다. 크롬에서 파이어 폭스로 바뀌기 전까지는 내가 찾은 예제 중 아무 것도 작동하지 못했습니다. 예를 들어, 유래 문제의 코드 : 나는 단순 여기를 쓰기 HTML5 File api, reading in an xml/text file and displaying it on the page? :html5 + javascript에서 텍스트 파일을 읽는 중 결과는 브라우저에 따라 다릅니다.
<!DOCTYPE html>
<html>
<head>
<title>reading xml</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>
<script>
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// Loop through the FileList
for (var i = 0, f; f = files[i]; i++) {
var reader = new FileReader();
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
// Print the contents of the file
var span = document.createElement('span');
span.innerHTML = ['<p>',e.target.result,'</p>'].join('');
document.getElementById('list').insertBefore(span, null);
};
})(f);
// Read in the file
reader.readAsText(f);
// reader.readAsDataURL(f);
}
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
</script>
</body>
파이어 폭스에서 잘 작동합니다. 나는 크롬으로 작동하지 않습니다. 나는 무엇이 없는가?! 감사.
내가 크롬 18.0.1025.168을 사용하고 있습니다 (개발자는 134,367 리눅스 빌드가) 우분투 11.10
크롬 (22)와 나는 손을 가졌던와 크롬 15에서 나를 위해 작동합니다. (http://jsfiddle.net/EYrdE/). 다른 텍스트 파일을 사용해 보셨습니까? 어쩌면 번역에서 뭔가를 잃어 버렸을 수도 있습니다. 콘솔에 오류가 있는지 확인 했습니까? –