问题:在表单提交后关闭和销毁cfwindow的代码-必须更改为使用iFrame (以适应文件上传)。现在“关闭”不起作用了。
如何关闭包含iframe的cfwindow ...iframe表单提交后?
流程:
基页->打开窗口
窗口包含iframe;iframe ->调用窗体页
表单页面->提交到操作页面(同一页)
操作页面->上传文件并执行其他表单处理-关闭窗口。
=====
注意:为了便于阅读,我已经将代码简化为精华……如果JS代码块需要(或“应该”)到其他地方,并以其他方式引用-请让我知道……
基页- basePage.cfm:
<script>
function launchWin(name,url) {
ColdFusion.Window.create(name+'_formWindow', name, url,
{ height:500,
width:500,
modal:true,
closable:true,
draggable:true,
resizable:true,
center:true,
initshow:true,
minheight:200,
minwidth:200
})
}
</script>
<a href="javascript:launchWin( 'Attachment', 'iframe.cfm?id=101' );" >ATTACH</a>
<DIV ID="myContent"></div>===========================================
窗口页面- iframe.cfm - (iframe):
<iframe src="attachment.cfm?id=101"></iframe>===========================================
IFRAME SRC - attachment.cfm (注意-此代码在将其放入iFrame时有效):
<script>
ColdFusion.Window.onHide( 'Attachment_formWindow', cleanup );
function cleanup() {
ColdFusion.Window.destroy( 'Attachment_formWindow', true );
}
</script>
<!--- HANDLE THE FORM --->
<cfif structKeyExists( FORM, 'add_Attachment' ) >
<!--- Do CFFILE to handle file upload --->
<cffile action="upload"
destination="C:\"
filefield="theFile"
nameconflict="makeunique">
<!--- other form processing goes here (not relevant to question at hand) --->
<!--- refresh the calling page, and close this window - destroy it so contents don't presist --->
<script>
ColdFusion.navigate( 'basePage.cfm?', 'myContent' );
ColdFusion.Window.hide( 'Attachment_formWindow' );
</script>
</cfif>
<!--- form to get information --->
<cfform name="attachmentForm" enctype="multipart/form-data" >
<table>
<tr><td>FILE:</td><td><cfinput type="file" name="theFile" size="40" /></td></tr>
<tr><td>TITLE:</td><td><cfinput type="text" name="name" value="" size="40" maxlength="100" /></td></tr>
<tr><td>DESCRIPTION:</td><td><cftextarea name="description" cols="40" rows="10"></cftextarea></td></tr>
<tr><td></td><td><cfinput type="submit" name="add_Attachment" value="Add" /></td></tr>
</table>
</cfform> 发布于 2012-02-09 08:28:23
当您将代码移动到iframe时,您必须更改javascript中的引用以引用div,因为iframe引入了它自己的子上下文(vs. a parent.,它位于原始上下文中)。
试试这个:
<script>
parent.ColdFusion.Window.onHide( 'Attachment_formWindow', cleanup );
function cleanup() {
parent.ColdFusion.Window.destroy( 'Attachment_formWindow', true );
}
</script>
<!--- HANDLE THE FORM --->
<cfif structKeyExists( FORM, 'add_Attachment' ) >
<!--- Do CFFILE to handle file upload --->
<cffile action="upload"
destination="C:\"
filefield="theFile"
nameconflict="makeunique">
<!--- other form processing goes here (not relevant to question at hand) --->
<!--- refresh the calling page, and close this window - destroy it so contents don't presist --->
<script>
parent.ColdFusion.navigate( 'basePage.cfm?', 'myContent' );
parent.ColdFusion.Window.hide( 'Attachment_formWindow' );
</script>
</cfif>
<!--- form to get information --->
<cfform name="attachmentForm" enctype="multipart/form-data" >
<table>
<tr><td>FILE:</td><td><cfinput type="file" name="theFile" size="40" /></td></tr>
<tr><td>TITLE:</td><td><cfinput type="text" name="name" value="" size="40" maxlength="100" /></td></tr>
<tr><td>DESCRIPTION:</td><td><cftextarea name="description" cols="40" rows="10"></cftextarea></td></tr>
<tr><td></td><td><cfinput type="submit" name="add_Attachment" value="Add" /></td></tr>
</table>
</cfform> https://stackoverflow.com/questions/9197306
复制相似问题