问题
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