使用Jquery关闭Iframe

Close Iframe With Jquery?

本文关键字:Iframe 关闭 Jquery 使用      更新时间:2023-09-26

我知道有很多这样的问题,但我们已经知道每个案例都不一样。

所以,这是我的例子:

HTML输出:PAGE 1

<div id="login-embedded" style="height: 401px; display: none;">
<iframe frameborder="0" src="{$mybb->settings['bburl']}/login.php" style="height: 401px;"></iframe>
</div> <!-- /end login-embedded -->
<div id="blackout"></div>

HTML输出:IFRAME

<div id="embedded-login">
<h1>{$lang->login}</h1>
<form method="post" action="{$mybb->settings['bburl']}/member.php">
<a id="embedded-close" href="javascript:;" onclick="jQuery('#blackout, #login-embedded').hide('slow');" rel="closeLogin"></a>
<div>
......
</div>
JQUERY:

jQuery(document).ready(function(){
jQuery('a[name="login"]').click(function(){
    jQuery("#blackout").fadeIn(1000);
    jQuery("#blackout").fadeTo("slow",0.8);
    jQuery("#login-embedded").show();
    return false
});
jQuery("#embedded-login a#embedded-close").click(function(){
    jQuery("#blackout").hide("slow");jQuery("#login-embedded").hide("slow");
    return false
});
jQuery("#blackout").click(function(){
    jQuery(this).hide("slow");
    jQuery("#login-embedded").hide("slow");
    return false
})
});

我错过什么了吗?我找到了一个解决方案,通过使用jquery对话框关闭iframe,但似乎它不能在我的情况下工作。

任何帮助将不胜感激!谢谢!

您的onclick="jQuery('#blackout, #login-embedded').hide('slow');"在iframe中不会做任何事情,因为这些元素在父页面上。试试这个:

onclick="window.parent.jQuery('#blackout, #login-embedded').hide('slow');"

window.parent.jQuery位将使用父文档的jQuery实例来运行动画