Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
739 views
in Technique[技术] by (71.8m points)

javascript - Browser Auto Select file through File Input Tag via Browser Extension

I want to auto select a file through
File input tag < input type=file > via java script ?

I know this is security issue and not allowed normally.

But is this allowed through extensions or in any form in any browser,

because i m working on a automation project
which requires posting of a form with multiple values has upload feature which uploads file first and then posts form(kijiji.ca)

and need this to be done.

need not to be browser specific any browser which have automation capability like chrome, Fire fox

Further reuquirement

Hi Wladimir, i got it working as Wladimir suggested in Extension scope.

Can u tell me if i need to auto select multiple files what value should i set.

I tried setting this

input.value = '"D:Tempstep1.jpg" "D:Tempstep2.jpg" "D:Tempstep3.jpg"'

but it don't accept it. Though i can set it to single image and it takes it..

thanks..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Firefox extensions are allowed to set input.value property so something like this will work:

input.value = "c:\autoexec.bat";
input.form.submit();

However, when using Add-on SDK a content script will likely not have the necessary privileges (needs to be tested). In this case one would need to use chrome authority and access the web page directly rather than via a content script.

As to Chrome, extensions there don't have access to the file system - so the security restrictions that apply to web pages are applying to extensions as well. Allowing extensions to set the value of a file upload widget would be a security issue there. So I'm pretty sure that it isn't possible.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...