IE8 causing FILE input entry to be blank via SendKeys

天大地大妈咪最大 提交于 2019-12-11 16:03:36

问题


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.


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/973661/ie8-causing-file-input-entry-to-be-blank-via-sendkeys

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!