jayarjo
jayarjo

Reputation: 16726

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?

Upvotes: 5

Views: 7644

Answers (2)

Joe
Joe

Reputation: 15802

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(); };

Upvotes: 13

Soufiane Hassou
Soufiane Hassou

Reputation: 17750

HTML:

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

JS:

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

Upvotes: 3

Related Questions