JS - file onload() 不适用于安卓浏览器



我有一个类似于示例http://jsfiddle.net/jonathansampson/K3A9r/的应用程序但是如果我将这个概念用于iPad/android上的文件上传,它就不起作用了。无论使用onload()还是onloadend()都不会将图像加载到浏览器中

html:

<input type="file" name="myFileSelect" />

js:

 // Bind to the change event of our file input
$("input[name='myFileSelect']").on("change", function(){
// Get a reference to the fileList
var files = !!this.files ? this.files : [];
// If no files were selected, or no FileReader support, return
if ( !files.length || !window.FileReader ) return;
// Only proceed if the selected file is an image
if ( /^image/.test( files[0].type ) ) {
    // Create a new instance of the FileReader
    var reader = new FileReader();
    // Read the local file as a DataURL
    reader.readAsDataURL( files[0] );
    // When loaded, set image data as background of page
    reader.onloadend = function(){
        $("html").css("background-image", "url(" + this.result + ")");
    }
   }
});

我不认为onloadend事件在android或ios中得到很好的支持。我想ie10也不支持FileReader上的这个事件。也许你应该依靠onload事件来代替。

文件。API工作于android浏览器3.0+或android设备上的firefox用户

http://mobilehtml5.org/

最新更新