0

I have a file upload function on my website, it works correctly on Chrome, Safari, IE 7 & 10, but it just doesn't work with FireFox 23.0.1.

Here is the code:

HTML:

<iframe style="display:none" src="about:blank" id="up_frame" name="up_frame" onload="iFrameDone()"></iframe>

JavaScript:

function Create(tag,type,obj){
    var n = document.createElement(tag);
    if(type) n.type = type;
    n.id = UniqueId();
    obj.appendChild(n);
    return n;
}
.
.
.
fm = Create("form",null,uplButton);
fl = Create("input","file",fm);
fl.name = "up_file";
if(ie){
   // Keep Internet Explorer from complaining
   // move the from to a proper place & apply some styles.
}else{
    fm.Opacity(0);  // make it transparent
}
fl.onchange = function(){
   fm.method = "post";
   fm.encoding = "multipart/form-data";
   fm.action = "upload";
   fm.target = "up_frame";
   fm.submit();
}

Basically what I'm doing is to create a form on the top of my Upload button, and then making it transparent, a trick to achieve visual uniformity in my design. When the user selects a file, the onchange event is triggered and the form submitted through a hidden iframe.

This works perfect on Chrome and Safari. In order to make it work on IE I had to keep the form visible because otherwise it complaints: "access denied", that's the why of the if, but as you can see, the form submission mechanism is the same for all browsers.

I traced the code with the FF debugger and at the point at which submit is about to be executed all the members of fm contain the expected values, but if I click on the Single Step button to execute fm.submit(), it seems to just skip the instruction without doing anything at all, nothing is sent to the server and no error/warning message is logged at the console, so I have no clue of what's going on.

PLEASE NOTE THAT:

In order to discard a similar problem like the one I had with IE, I tested with the form visible but still get the same behavior.

ALSO NOTE THAT:

This trick or a similar one is being used for all major email services, so there is a way to make it work, please don't give me answers like: "add a submit button".

This means no security problem, since I am not trying to force the upload of a specific file. What I'm trying to do is to pop up the "File upload" window and upload the file that the user chooses by his/her own free, aware and conscious will. But if the browsers does consider it a security issue then why it is not logged in the console? or otherwise reported to the user.

4

1 回答 1

1

解决后:卸载FF,从Mozilla官方网站下载并重新安装。作为记录:如果您打算安装 Fire Fox,请确保您是从 Mozilla 官方网站下载的...

发生这种情况是因为我忽略了我的防病毒软件给我的关于我下载第一个安装包的站点的警告。

于 2013-09-10T13:40:13.813 回答