JavaScript readAsDataurl is not a function

不羁的心 提交于 2019-12-23 09:32:05

问题


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]);

回答1:


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.



来源:https://stackoverflow.com/questions/30272619/javascript-readasdataurl-is-not-a-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!