【问题标题】:jquery reload iframe after opening sliding paneljquery在打开滑动面板后重新加载iframe
【发布时间】:2013-06-13 20:01:34
【问题描述】:
<script type="text/javascript">
$(document).ready(function(){
    $(".trigger").click(function(){
        $(".shoutpanel").toggle("fast");
        $(this).toggleClass("active");
        return false;
    });
});
</script>

<a class="trigger" href="#">Shoutbox</a>


<div class="shoutpanel">
<iframe id="shoutbox" name="shoutbox" width="350" height="480" src="tchat.php">
</iframe>
</div>

此脚本将切换一个带有喊话框的滑动面板。 如果我将喊话框放在滑动面板之外,那么它会在加载后立即自动向下滚动(以显示最后一次喊叫) 但是由于某些未知原因,当我将喊话框放在滑动面板中时,除非我手动刷新它,否则它不会向下滚动。

所以我试图找到一种解决方法,我考虑将触发脚本设置为在执行时自动刷新shoutbox iframe。因此,当您单击触发器时,它会在打开滑动面板后刷新喊话框

我不是 jquery 专业人士,所以我自己无法做到......基本上我只需要这样的东西:

$(document).ready(function(){
$(".trigger").click(function(){
    $(".shoutpanel").toggle("fast");
    $(this).toggleClass("active");
    return false;
            document.getElementById(shoutbox).contentDocument.location.reload(true);
});
});

【问题讨论】:

    标签: javascript jquery iframe panel


    【解决方案1】:

    几个问题:

    • 您的点击事件中有一个 return false(这不是必需的),而且它在您的 reload 语句之前。所以它永远不会执行。
    • document.getElementById(shoutbox) 的 id 应该用引号括起来。
    • 即使在上滑期间,您也始终会重新加载 iframe。

    试试这个:

    $(document).ready(function () {
        $(".trigger").click(function () {
            $(".shoutpanel").toggle("fast", function () { //Use toggle's complete function 
                if ($(this).is(':visible')) {   // check if this is in visible mode
                  document.getElementById("shoutbox")
                        .contentDocument.location.reload(true); //reload the iframe
                }
            });
            $(this).toggleClass("active");
    
        });
    });
    

    Fiddle

    【讨论】:

    • 完美运行。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-07
    相关资源
    最近更新 更多