Is it possible to prevent the file dialog from appearing? What for?

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

+4
source share
2 answers

Soufiane code requires a jQuery Javascript library to be created on your page. If you don't have one, 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(); }; 
+9
source

HTML:

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

JS:

 $('.openf').click(function(e){ e.preventDefault(); }); 
+2
source

All Articles