javascript - file input does not update except in Chrome -
i have local program writes json object file javascript can pick data , process it. file selected using <input>
object:
<form id = "getfiles"> <input type = "file" multiple id = "files" /> </form>
with following js function setinterval
repeat every 300ms. however, when file changes, google chrome reloads file , processes new content; have manually reselect file on page in ie 10 , firefox 20.
function speaktext() { var thefile = document.getelementbyid('files').files[0]; var lastchanged = thefile.lastmodifieddate; var reader = new filereader(); reader.onload = function(event) { var lcd = document.getelementbyid("last_change_date"); if (!lcd) { var spanlastchanged = document.createelement("span"); spanlastchanged.id = "last_change_date"; spanlastchanged.innertext = lastchanged; console.log(lastchanged); document.body.appendchild(spanlastchanged); } else { // compare lastchanged last_change_date var last_known_change = date.parse(lcd.innertext); // var last_known_change = date.parse(thefile.lastmodifieddate); if (last_known_change !== date.parse(lastchanged)) { console.log("something new since " + lcd.innertext); var filecontent = event.target.result; var commands = json.parse(filecontent); handlejson(filecontent); lcd.innertext = lastchanged; } } } reader.readastext(thefile, "utf-8"); }
firefox , ie doing right thing per spec: file objects associated file input supposed immutable snapshots of file @ point when file object created. it's known bug in webkit/blink store reference file's data, mutating data change file object sees.
in fact, webkit/blink behavior privacy bug: when user selects file in file input, giving web page permission read data of file at time, not future versions of file! why spec written is.
Comments
Post a Comment