如何使用javascript或jQuery关闭iframe内的iframe?我试过<a href="javascript:self.close()">
但它没有奏效。如何在iframe内关闭iframe
33
A
回答
58
“关闭”当前的iFrame是不可能的,但您可以告诉父母操纵dom并使其不可见。
在IFrame:请
parent.closeIFrame();
在父:
function closeIFrame(){
$('#youriframeid').remove();
}
11
function closeWin() // Tested Code
{
var someIframe = window.parent.document.getElementById('iframe_callback');
someIframe.parentNode.removeChild(window.parent.document.getElementById('iframe_callback'));
}
<input class = question name="Close" type ="button" value = "Close" onClick = "closeWin()" tabindex="10" />
2
使用此功能可以从母公司的iframe本身
frameElement.parentNode.removeChild(frameElement)
它与同一产地内删除IFRAME只(不允许与十字架杜松子酒)
1
同类哈克,但它工作得很好十岁上下
function close_frame(){
if(!window.should_close){
window.should_close=1;
}else if(window.should_close==1){
location.reload();
//or iframe hide or whatever
}
}
<iframe src="iframe_index.php" onload="close_frame()"></iframe>
那么帧
$('#close_modal_main').click(function(){
window.location = 'iframe_index.php?close=1';
});
里面,如果你想通过
if(isset($_GET['close'])){
die;
}
获得幻想在你的框架页面的顶部,使重新加载不明显
所以基本上在第一时间框架加载它不隐藏自身,但它加载ITLL调用的onload函数和家长将有下一次的窗口VAR导致框架关闭
1
这个解决方案没有工作了因为我在跨域的方案创建像Pinterest的Pin It这样的书签。
我在GitHub https://gist.github.com/kn0ll/1020251上发现了一个小书签模板,它解决了关闭从其中发送命令的Iframe的问题。
既然不能在iframe中访问父窗口的任何元素,这种沟通只能进行发布使用window.postMessage
所有这些步骤都GitHub的链路上的两个窗口之间的事件:
1-您必须在父页面上注入JS文件。
2 - 在这个文件中注入父,添加一个窗口事件听者
window.addEventListener('message', function(e) {
var someIframe = window.parent.document.getElementById('iframeid');
someIframe.parentNode.removeChild(window.parent.document.getElementById('iframeid'));
});
此侦听器会处理你想
3-您发送的iframe页面内密切和任何其他事件通过postMessage的关闭命令:
$(this).trigger('post-message', [{
event: 'unload-bookmarklet'
}]);
按照上https://gist.github.com/kn0ll/1020251模板,你会没事的!
希望它能帮助,
相关问题
- 1. 如何关闭iframe?
- 2. 如何从该iframe中关闭iframe
- 3. 如何关闭全屏iframe?
- 4. 如何关闭iframe窗口?
- 5. Lightbox iframe关闭
- 6. 如何在asp.net中关闭(javascript iframe)?
- 7. 如何关闭弹出的iframe在HTML
- 8. 如何在点击时关闭iframe?
- 9. 关闭IFRAME窗口
- 10. 关闭粗框iFrame
- 11. 自动关闭iframe
- 12. 从iframe关闭fancybox
- 13. 关闭一个IFRAME
- 14. jquery:Colorbox关闭iFrame onsubmit
- 15. 用jquery关闭iframe?
- 16. 检测iframe何时关闭
- 17. 用IE关闭iframe中的iframe
- 18. iFrame内的彩盒 - 从父项关闭
- 19. 如何使用javascript关闭colorbox iframe?
- 20. 如何关闭的fancybox iframe中提交
- 21. 如何从JavaScript关闭modalframe iframe?
- 22. 如何用javascript/jquery关闭iframe?
- 23. 正确关闭iframe中的iframe并且不隐藏iframe
- 24. SimpleModal - 用关闭按钮关闭iframe
- 25. js iframe关闭按钮
- 26. 关闭使用iframe的cfwindow
- 27. 从iframe调用colorbox关闭
- 28. 只关闭iframe上的javascript
- 29. colorbox关闭按钮与iframe
- 30. 关闭里面的iframe
如果你不想依靠入侵尝试我的答案在http://stackoverflow.com/questions/6086986/how-do-i-remove-an-iframe-from -within-that-that-been-dynamic-created – Rhys