iframe和javascript问题,我无法不刷新就关闭iframe. [英] Iframe and javascript issue where i am not able to close an iframe without refresh.

查看:115
本文介绍了iframe和javascript问题,我无法不刷新就关闭iframe.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我在一个页面中使用了iframe,该iframe在asp.net主页上看起来像div.在iframe页面中,我有一个关闭按钮,当我单击关闭按钮时,我在iframe页面中调用了一个javascript函数,其代码为:

window.location.href ="Pagename.aspx";

该行关闭了iframe,但是包含iframe的主页在关闭iframe后会刷新,因此....我尝试了多种方式来关闭iframe,而无需引用

window.close();

但它不起作用.关闭iframe的主要问题是close btn本身位于iframe页面中,因此,如果我编写代码以关闭iframe页面中的iframe无法使用.....


因此,您能否帮助我解决此问题..那就是关闭iframe而不刷新包含iframe的主页.在此先感谢您!!

Hi, I am using an iframe in a page where the iframe looks like a div on the main asp.net page. In the Iframe page i have got a close button and when i click on close button i am calling a javascript function in iframe page which is having the code as:

window.location.href = "Pagename.aspx";

this line closes the Iframe but the main page which contains Iframe refreshes after closing the iframe so.... I tried in many ways to close the iframe without refres like

window.close();

but it is not working. The main problem to close the iframe is that the close btn is in the iframe page it self so if i write the code to close iframe in iframe page that does not work.....


So, can u please help me solve this issue .. that is closing of iframe without refreshing main page that contains iframe. Thanking you in advance!!

推荐答案

您将需要销毁iframe组件. I框架不是窗口.所以window.close不会做任何事情.但是,您可以在顶层窗口中调用一个函数.只要您iframe的内容在同一个域中即可.

因此,您不用window.close()而是使用window.parent.closeIframe();

在父窗口中,您将需要一个函数closeIframe();

You''ll need to destroy the iframe component. An I frame is not a window. So window.close won''t do anything. You can however call a function in the top level window. As long as the content of you iframe is in the same domain.

So instead of window.close() you do window.parent.closeIframe();

The in the parent window you''ll need a function closeIframe();

function closeIframe() {
   var ifram=document.getElementById("iframe-id");
   iframe.parent.removeChild(iframe);
}



诸如此类.



Something like that.


这篇关于iframe和javascript问题,我无法不刷新就关闭iframe.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆