Question

Application: HTA (therefore IE) This is an application that uses SendKeys to populate a FILE input field.

Issue: File is never uploaded.

Description: An offscreen form (invisible to user) uploads a file to the server. The file input is entered via SendKeys (javascript). Appears to be isolated to when IE8 is installed.


Does anyone know of what may be causing this and any workarounds?

Sorry for lack of information. I will edit the question with additional information if no answers are submitted.

Was it helpful?

Solution

IE8 has set the <input type="file"> element to read-only in order to prevent security attacks. (see article).

Therefore a programmatic way isn't possible.

OTHER TIPS

I actually solved this problem with an interesting trick. Here's how...

Create an external vbscript 'include file' called 'vbshelper.inc' which contains the following code:

function stuffKeys(x)
    Set wshShell = CreateObject("WScript.Shell")
    wshShell.Sendkeys(x)
end function

Inside your HTML code header, place the following lines as your first < Script> element...

<Script language="VBScript" src="vbshelper.inc">

 function defaultFldr()
    stuffKeys(" C:\Temp\*.txt~")
 end function

function do_something()
.
.
. etc
end function

</Script>

[Note-1 There is a space before the C in ' C:\Temp\*.txt~' and a tilde ( ~ ) after the .txt.]

[Note-2 I had to specify Script type=VBScript and not type="text/vbscript". I'm not sure why this is required.]


later, in your HTML code, create the button like this...

<input type="File" id="srcFile" onchange="do_something()" onclick="defaultFldr()">

[Note-3: I tried to call the stuffKeys function right from the onclick command, but it didn't work. Probably because you have to use single quotes around the folder string.]

So... You can't create the WScript object from within an HTML or HTA page, but it works when referenced from an external include file. Keep the 'vbshelper.inc' file in the same folder as your HTML or HTA file.

Is it possible to use compatibility mode in IE8 as a work-around?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top