最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

filereader - JavaScript readAsDataurl is not a function - Stack Overflow

programmeradmin0浏览0评论

In Gecko/Firefox I got the error message:

TypeError: fr.readAsDataurl is not a function

Using the following JavaScript:

var fr = new FileReader();
fr.readAsDataURL(files[i]);

In Gecko/Firefox I got the error message:

TypeError: fr.readAsDataurl is not a function

Using the following JavaScript:

var fr = new FileReader();
fr.readAsDataURL(files[i]);
Share Improve this question asked May 16, 2015 at 6:37 JohnJohn 13.8k15 gold badges111 silver badges190 bronze badges 4
  • @MartijnPieters I asked the question in the fashion others who will encounter it would ask and posted the answer in the fashion fitting to the situation. Are you suggesting that I post the answer inside of the question? That wouldn't make logical sense. – John Commented May 16, 2015 at 14:23
  • 1 Ah, sorry, I missed that you had created a self-answer here. My mistake! – Martijn Pieters Commented May 16, 2015 at 14:42
  • 1 Thanks . Ran into the same problem – 32teeths Commented Jul 2, 2015 at 0:29
  • 1 @32teeths The best way to thank on Stack is up-voting questions and/or answers. I post in spite of the fact that people are in a rush to down-vote what I post to help people. – John Commented Jul 2, 2015 at 19:34
Add a ment  | 

1 Answer 1

Reset to default 9

As it turns out someone at Mozilla created the deprecated method readAsDataurl with the improper letter casing and since JavaScript is case sensitive I simply had to use the readAsDataURL method (uppercase URL):

if (fr.readAsDataURL) {fr.readAsDataURL(files[i]);}
else if (fr.readAsDataurl) {fr.readAsDataurl(files[i]);}

Note that the standard/proper casing method is detected first. If you want your code to work as quickly as possible performance will improve over time as standards support improves.

发布评论

评论列表(0)

  1. 暂无评论