获取错误在IE中拒绝WebPage访问

时间:2013-04-04 09:21:35

标签: javascript html file-upload upload

我用$('#dropbox')打开文件对话框。点击 然后选择要上传的文件。然后在Firefox成功文件上传中单击按钮上传文件但在IE中获取错误WebPage访问被拒绝( line 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中我需要什么?

1 个答案:

答案 0 :(得分:0)

您无法实际(通过Javascript)单击文件输入元素,然后通过Javascript提交关联的表单。 IE将不会允许这样做。您的工作流程被视为安全违规。你需要重新思考你的方法。