1

我正在使用 $('#dropbox').click 打开文件对话框,然后选择要上传的文件。然后在 Firefox 成功文件上传但在 IE Get Error WebPage Access is denied 中单击按钮上传文件(行 form.submit();)。

$(document).ready(function(){
if((support.fileReader==false)&&(support.formData==false)){
$('input[type=button]').eq(0).attr("onClick",'fileUpload(this.form,"UploadHandler.ashx","upload");returnfalse;');
$('input[type=file]').eq(0).attr("onchange","fileSelectedIE();");
}
$('#dropbox').click(function(){
$('input[type=file]').click();
});
});
functionfileUpload(form,action_url,div_id){
//Createtheiframe...
variframe=document.createElement("iframe");
iframe.setAttribute("id","upload_iframe");
iframe.setAttribute("name","upload_iframe");
iframe.setAttribute("width","0");
iframe.setAttribute("height","0");
iframe.setAttribute("border","0");
iframe.setAttribute("style","width:0;height:0;border:none;");
//target="#fileIframe"
//Addtodocument...
form.parentNode.appendChild(iframe);
window.frames['upload_iframe'].name="upload_iframe";

iframeId=document.getElementById("upload_iframe");

//Addevent...
vareventHandler=function(){

if(iframeId.detachEvent){
iframeId.detachEvent("onload",eventHandler);
$('#progressNumber').text("100%");
}
elseiframeId.removeEventListener("load",eventHandler,false);
if(iframeId.addEventListener)iframeId.removeEventListener("progress",uploadProgress1,false);
//Messagefromserver...
if(iframeId.contentDocument){
content=iframeId.contentDocument.body.innerHTML;
}elseif(iframeId.contentWindow){
content=iframeId.contentWindow.document.body.innerHTML;
}elseif(iframeId.document){
content=iframeId.document.body.innerHTML;
}

document.getElementById(div_id).innerHTML=content;

//Deltheiframe...
setTimeout('iframeId.parentNode.removeChild(iframeId)',250);
}

if(iframeId.addEventListener){
iframeId.addEventListener("load",eventHandler,true);
$('#progressNumber').text("Processing...");
}
if(iframeId.attachEvent)iframeId.attachEvent("onload",eventHandler);
//if(iframeId.addEventListener)iframeId.addEventListener("progress",uploadProgress1,false);

//Setpropertiesofform...
form.setAttribute("target","upload_iframe");
form.setAttribute("action",action_url);
form.setAttribute("method","post");
form.setAttribute("enctype","multipart/form-data");
form.setAttribute("encoding","multipart/form-data");
//Submittheform...
**form.submit();**

document.getElementById(div_id).innerHTML="Uploading...";
}
functionfileSelectedIE(){
varfullname=$('#fileToUpload').val().toString();
varIndexExt=fullname.lastIndexOf(".");
varext=fullname.substr(IndexExt+1).toString();
varIndexFileName=fullname.lastIndexOf("\\");
varFileName=fullname.substring(IndexFileName+1,IndexExt).toString();
document.getElementById('fileName').innerHTML='Name:'+FileName;
document.getElementById('fileSize').innerHTML='Size:NotSupport';
document.getElementById('fileType').innerHTML='Type:'+ext;
}

<div id="dropbox"></div>
<input type="file" name="fileToUpload[]" id="fileToUpload" /></br>
<input type="button" value="upload"/>

我在 IE 中需要什么?

4

1 回答 1

0

您不能务实地(通过 Javascript)单击文件输入元素,然后通过 Javascript 提交关联的表单。IE 根本不允许这样做。您的工作流程被视为违反安全规定。您将需要重新考虑您的方法。

于 2013-04-04T12:03:00.757 回答