12280

IE8 causing FILE input entry to be blank via SendKeys

Question:

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

<strong>Issue</strong>: File is never uploaded.

<strong>Description</strong>: 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.

<hr />

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

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

Answer1:

IE8 has set the <input type="file"> element to read-only in order to prevent security attacks. (see <a href="http://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx" rel="nofollow">article</a>).

Therefore a programmatic way isn't possible.

Answer2:

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 <hr />

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.]

<hr />

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.

Answer3:

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

Recommend

  • Accesing properties in a UserControl from the MainWindow (WPF/MVVM)
  • Scala Slick Database Views
  • Is it possible to access raw iphone audio output?
  • Sticky Service not restarting after RAM full on Xiaomi / Huawei / Lava
  • mail server requires authentication when attempting to send to a non-local e-mail address when using
  • BizTalk Party not being resolved for incoming HL7v2 message
  • No rows to manipulate in html table created with jQuery csvToTable?
  • HTML checkbox form and HTTP URL
  • The symbol you provided is not a function
  • abstracting over a collection
  • how to set variables in a php include file?
  • Can I programmatically choose the Android layout folder?
  • C: Incompatible pointer type initializing
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • How to define and use opencv mat of user type
  • Extracting HTML between tags
  • ilmerge with a PFX file
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • vba code to select only visible cells in specific column except heading
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Weird JavaScript statement, what does it mean?
  • Web-crawler for facebook in python
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How to set the response of a form post action to a iframe source?
  • How do I configure my settings file to work with unit tests?
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Django query for large number of relationships
  • Busy indicator not showing up in wpf window [duplicate]
  • reshape alternating columns in less time and using less memory
  • costura.fody for a dll that references another dll
  • Binding checkboxes to object values in AngularJs
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal