首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >关闭使用iframe的cfwindow

关闭使用iframe的cfwindow
EN

Stack Overflow用户
提问于 2012-02-09 00:23:07
回答 1查看 874关注 0票数 0

问题:在表单提交后关闭和销毁cfwindow的代码-必须更改为使用iFrame (以适应文件上传)。现在“关闭”不起作用了。

如何关闭包含iframe的cfwindow ...iframe表单提交后?

流程:

基页->打开窗口

窗口包含iframe;iframe ->调用窗体页

表单页面->提交到操作页面(同一页)

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

=====

注意:为了便于阅读,我已经将代码简化为精华……如果JS代码块需要(或“应该”)到其他地方,并以其他方式引用-请让我知道……

基页- basePage.cfm:

代码语言:javascript
复制
<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):

代码语言:javascript
复制
<iframe src="attachment.cfm?id=101"></iframe>

===========================================

IFRAME SRC - attachment.cfm (注意-此代码在将其放入iFrame时有效):

代码语言:javascript
复制
<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> 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-09 08:28:23

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

试试这个:

代码语言:javascript
复制
<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> 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9197306

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档