1

In WebKit the onchange only triggers when the file changes, in Firefox not. It's a known issue, but I only find how to make chrome behaves like Firefox and not the oposite.

var control = $('label.empty > input');    
$(control).on('change', function(){});

How can I make this working in firefox only when the file changes?

Related.

Community
  • 1
  • 1
rbsteiner
  • 13
  • 2

2 Answers2

0

You can try this,

If the file input is

<input type="file" id="fileId"/>

Javascript code -

document.getElementById("fileId").addEventListener("change", function(){
console.log("file changed...");
// put you on change code here
},false);
Rakesh Chouhan
  • 1,196
  • 12
  • 28
0

You could store the old value of the file input and check it to the new one.
If it matches, return; else it's a new one.

document.querySelector('input').addEventListener('change', function(){
    if(this.__value__===this.value) return;
    this.__value__=this.value;
    alert('new One!');
    });
<input type="file">
Kaiido
  • 123,334
  • 13
  • 219
  • 285
  • Do you know how can I reset this.__value__ from the outside? I mean If the user deletes the file he can't upload the same file because this.__value__ still holds the value. – rbsteiner Apr 22 '15 at 15:15
  • the solution I gave you stores the old value into the element, but if you prefer, you can also store it in any variable (e.g in global scope). Now, if you keep this way of storing (which has the benefit of not populating the window's scope with unnecessary garbage ), to access it, you'll have to first set a pointer to that element `document.querySelector('input')` in the example and then change its `__value__` property : `function resetTheInputValue(){ document.querySelector('input').__value__ = "";}` – Kaiido Apr 22 '15 at 15:21