关闭使用iframe的cfwindow

时间:2012-02-08 16:23:07

标签: javascript iframe coldfusion

ISSUE:在表单提交后用于关闭和销毁cfwindow的代码 - 将HAD更改为使用iFrame(以适应文件上载)。现在'关闭'不起作用。

如何关闭包含iframe的cfwindow ...一旦提交了iframe表单????

FLOW:

基页 - >打开窗口

窗口包含iframe; iframe - >调用表格页面

表单页面 - >提交到行动页面(同页)

操作页面 - >上传文件并进行其他表格处理 - 关闭窗口。

=====

注意:我已经将代码简化为本质 - 为了便于阅读...如果JS的块需要(或“应该”)去其他地方并以其他方式引用 - 请告诉我...

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(注意 - 这段代码可以将b4放在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> 

1 个答案:

答案 0 :(得分:1)

当您将代码移动到iframe时,您必须更改javascript中的引用以引用parent.,因为iframe引入了自己的子上下文(相对于div,它位于原始上下文中) )。

试试这个:

<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>