iframe下传文件
iframe上传文件
功能:父页面点击提交按钮后,iframe上传文件,文件上传成功则自动提交父页面数据,上传失败在iframe中显示出错信息。
父页面
父页面js
子页面
子页面js
功能:父页面点击提交按钮后,iframe上传文件,文件上传成功则自动提交父页面数据,上传失败在iframe中显示出错信息。
父页面
<s:form action="saveApply" namespace="/variation" theme="simple" enctype="multipart/form-data" method="post"> <iframe src="variation/toUpload.action?projectId=${projectId}" name="uploadFile" frameborder="0" scrolling="no" width="100%"></iframe> <input type="button" class ="input" value="<s:text name="i18n_Save" />" onclick="toUpload()" /> </s:form>
父页面js
function toUpload(){ window.frames["uploadFile"].uploadFile(); } function toSubmit(){ document.forms[0].submit(); }
子页面
<body onload="submitForm()"> <s:form action="saveFile" namespace="/variation" theme="simple" enctype="multipart/form-data" method="post"> <table class="table_add_issue" cellspacing="0" cellpadding="0"> <tr style="height:31px"> <td class="wdaddname"><s:text name="i18n_UploadVariation"></s:text></td> <td class="wdaddvalue"> <s:file name="uploadFile" /> <a href="variation/download.action"><s:text name="i18n_DownloadFileTemplate"></s:text></a> </td> </tr> </table> <s:hidden name="projectId" value="%{projectId}" /> <s:hidden name="fileFlag" value="%{fileFlag}" /> <div id="inputtip"> <s:property value="tip" /> <s:fielderror theme="simple" /> <s:actionerror theme="simple" /> </div> </s:form> </body>
子页面js
function uploadFile(){ document.forms[0].submit(); } function submitForm(){ var fileFlag = document.getElementsByName("fileFlag")[0].value; if(fileFlag==0){ }else if( fileFlag==1){ parent.toSubmit(); } }