开发者

input file onchange event not being fired in chrome

This is a weird thing i noticed in chrome. if the user select a file and then select the same file again bu opening the file dialog again, chrome doesn't fire the onchange event while firefox does.

anybody 开发者_Go百科noticed it as well?


This is a known feature of Chrome and a quick Google on the topic will bring up some interesting discussions.

It makes sense to me that the change event wouldn't fire since nothing has changed (you're selecting the same file)

As for your question, what exactly are you asking? Are you looking for a way to change this behaviour or do you just want to know if we've noticed this as well?

If you want a way around this behaviour you can simply create a new file input in your Javascript and replace the previous one. This way your change event is guarenteed to fire.


function resetFileInput($element) {
  var clone = $element.clone();
  $element.replaceWith(clone);
}

And then use:

$('#element_id').on('change', function(){
...
});

Worked well for me!


An easier solution to reset an input file that works well for me :

document.getElementById('idOfInput').value = '';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜