Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to prevent file dialog from appearing? Why?

Suppose I have input[type=file] element and I want to intercept onclick event and prevent file dialog from appearing if conditions are not met. Is it possible? And why, if - not?

like image 533
jayarjo Avatar asked Sep 08 '11 14:09

jayarjo


2 Answers

Soufiane's code requires that you have a Javascript library called jQuery on your page. If you don't have it, you can get it at http://www.jquery.com or use something in plain Javascript:

HTML

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

JS:

document.getElementById('openf').onclick = function (e) { e.preventDefault(); };
like image 102
Joe Avatar answered Sep 24 '22 17:09

Joe


HTML:

<input type="file" class="openf" />

JS:

$('.openf').click(function(e){
      e.preventDefault();
});
like image 44
Soufiane Hassou Avatar answered Sep 25 '22 17:09

Soufiane Hassou