I am working on a Chrome extension where I need to click on <input type='file' /> in javascript via jQuery to display the Save As dialog box. Yes, they told me - most browsers do not allow you to do this. However, I found something very strange - I can click on the file entry element (and open the "Save" popup) if I do this through the address bar, for example:
javascript: $("<input type='file' />").appendTo("body").click();
So, I thought that if I could do this, then of course I could do this from my script content ...
Obviously, I was wrong. Doing $("<input type='file' />").appendTo("body").click(); from my content, the script not only makes zilch in addition to adding the element, but even emulates the address bar and makes window.location = "javascript: $(\"<input type='file' />\").appendTo(\"body\").focus().click();"; also zilch.
My initial thought was that it might have been some kind of chrome limitation in content scripts, but I'm wrong - the jsShell extension that works through a content script can run commands and get my desired results without a hitch.
So, does anyone know why jsShell and the browser can click the input file and get the “Save” dialog, but my extension cannot? I tried to parse jsShell and understand how it works (although I don't see anything special about how it works), but it STILL does not work. And the console doesn't reveal anything - no errors, no warnings.
It makes my head overheat, so any help is much appreciated!
source share