I need to create a hidden input[type=file] field and a button
element. When you click the button an event is delegated to the file input so that a file dialog box opens. In modern brosers that is not a problem.
document.getElementById('readFile').onclick = function(){
var event = document.createEvent("MouseEvent");
event.initMouseEvent("click", false, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);
filesInput.dispatchEvent(event) ;
}
or simply filesInput.click()
where filesInput is reference to the input[type=file] and #readFile is a button .
However for some reason this does not work in Firefox 3.6 and my spec require browser support Firefox>=3.6 Is there any way to fake a mouse click event in Firefox 3.6 or will I just have to show that ugly default input?
I am not using JQuery or any other framework.