ISSUE: code that worked to close and destroy a cfwindow after form submit – HAD to be changed to use iFrame (to accommodate file upload). now the ‘close’ does NOT work.
how does one close a cfwindow that contains an iframe… once the iframe form is submitted????
FLOW:
Base page -> opens window
window contains iframe; iframe -> calls form page
form page -> submit to action page (same page)
action page -> uploads file and does other form processing – closes window.
=====
NOTE: I have reduced the code to the essence – for ease of reading… if blocks of JS need to (or ‘should’) go elsewhere and be referenced in some other way – please let me know…
BASE PAGE – 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>
===========================================
WINDOW PAGE – iframe.cfm – (iframe):
<iframe src="attachment.cfm?id=101"></iframe>
===========================================
IFRAME SRC – attachment.cfm (note – this code worked b4 putting it in an 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>
When you move code to an iframe, you have to change the references in the javascript to refer to the
parent., since the iframe introduces its own child context (vs. a div, which lives within the original context).Try this: