iframe上传文件
功能:父页面点击提交按钮后,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>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 cellspacing="0" cellpadding="0"> <tr style="height:31px"><td /><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>function uploadFile(){document.forms[0].submit();}function submitForm(){var fileFlag = document.getElementsByName("fileFlag")[0].value;if(fileFlag==0){}else if( fileFlag==1){parent.toSubmit();}}