【问题标题】:Prevent parent page from scrolling down to iframe防止父页面向下滚动到 iframe
【发布时间】:2015-01-13 22:43:10
【问题描述】:

我使用 iframe 嵌入了一个网站。每当父页面加载时,嵌入页面都会使父页面向下滚动到 iframe。我无法更改嵌入页面中的任何代码,我只能访问父页面。这是fiddle of the issue:

HTML:

<iframe src="http://store4549118.ecwid.com/#!/~/cart" width="100%" height="100%" id="Container"></iframe>

CSS:

body { margin-top: 100px; height: 1000px; } 

如何防止父页面向下滚动到 iframe?

【问题讨论】:

    标签: javascript jquery html css iframe


    【解决方案1】:

    您的问题是您为 iframe 使用了错误的 ID 值。

    container 换成asContainer,你应该很高兴。

    【讨论】:

    • 请看问题小提琴。我不想加载其他问题的页面,但问题中的那个页面。父页面向下滚动到 iframe,我想留在父页面的顶部。
    • 我的建议是让使用 JQuery 的解决方案起作用。您需要更改 ID 值以匹配您在问题中包含的 JQuery 函数中使用的 ID 值。
    【解决方案2】:

    用工作副本更新了您的jfiddle。您也没有加载 jquery,因此请确保是否要使用正在加载的 jquery

    $(document).ready(function() {
        $('#Container').attr("src", "//audio-surf.com/mypage.php?u=DJDavid98#favorites_container").on('load', function() {
            $(this).show();
        });
    });
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-12
    • 2022-12-18
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    • 2021-09-24
    相关资源
    最近更新 更多