[whatwg] Proposal: API to ask the user for a file

Ian Hickson ian at hixie.ch
Thu Aug 29 11:12:53 PDT 2013


On Mon, 29 Apr 2013, Jonas Sicking wrote:
> 
> I think all modern browsers intentionally let webpages create custom UIs 
> for <input type=file> by completely hiding the <input> and then 
> rendering a custom UI using various <div> and <span> tags. When the 
> custom UI is clicked the page calls myInputElement.click() in order to 
> bring up the file picker UI.
> 
> Gecko contains some anti-annoyance protections as to prevent the page 
> from spawning file picker dialogs indefinitely. This is done by hooking 
> up <input type=file>.click() to popup blocking infrastructure.

Turns out <input type=file>.click() wasn't specced yet. I've now specced 
it, along with hooking it up to the popup-blocking logic.


> So the API being requested here is actually available. But in a really 
> ugly way through the HTMLInputElement interface.
> 
> But I don't really buy the argument that we should supply a new one 
> because the existing API isn't "reliably available". If the current API 
> is problematic because there is no way to check if it works, then I'd 
> prefer to add a way to check if it works, rather than adding a whole new 
> API.

Yeah.


On Wed, 1 May 2013, JC wrote:
> 
> I guess I should have mention too that the existing API is not only 
> unreliable but also very inconvenient. Since the trick depends on the 
> "changed" event

Yeah, it's weird that the dialog doesn't block script (since the dialog is 
modal). But I would imagine that any new API we added for this would 
actually be "worse" in this regard; we'd probably end up with a 
Promise-based entirely async, non-modal UI.


> and there's no official way to clear the list of files selected the last 
> time, in order to ensure that the event is fired if the same file is 
> selected again the element has to be removed and replaced by a new one 
> every time the user selects a file

That will be resolved once this is fixed:

   https://www.w3.org/Bugs/Public/show_bug.cgi?id=22682

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'


More information about the whatwg mailing list