JS - file onload()不能与android浏览器一起工作

JS - file onload() doesn't work with android browser

本文关键字:android 浏览器 一起 工作 不能 file onload JS      更新时间:2023-09-26

我有一个类似于示例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/