开发者

Chrome FileReader Events not triggered

开发者 https://www.devze.com 2023-03-17 18:39 出处:网络
I\'m trying to read a file with the HTML5 FileReader API. This works fine in Firefox 5.0 but no event is fired in Chromium 12.0.742.112

I'm trying to read a file with the HTML5 FileReader API. This works fine in Firefox 5.0 but no event is fired in Chromium 12.0.742.112

<html>
  <head>
    <script type="text/javascript">
      function handle(evt) {
      var reader = new FileReader();
      var file = evt.files[0];
      console.log("handling: " + file.name);
      reader.onloadstart = function(e) { console.log("loadstart"); }
      reader.onload = function(e) { console.log("onloa开发者_JAVA技巧d"); console.log(e.target.result);  };
      reader.readAsText(file);
      }
    </script>
  </head>
  <body>
    <input type="file" id="input" onchange="handle(this)">
  </body>
</html>

Also the code given in this question Chrome FileReader is not working any more.

My grasp of HTML is rather crude and I cannot see what is wrong with those samples. Is this simply a Chromium bug or is Firefox non-conforming?

I can annotate the sample with ECMAScript5 passages, if this helps and makes things more clear.


The answer is written in the very page that you linked.

If you are on chrome, this code has to be running on a server (localhost or on a site). It won't work with a local file.

Your code logged all 3 messages when I ran it.

0

精彩评论

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