问题描述
当有人点击 iframe(子页面)中的链接时,如何让父页面滚动到顶部?问题是子页面将保留在页面的同一位置,因为 iframe 的高度比父页面大很多.
When someone clicks on a link within an iframe (child page), how do I get the parent page to scroll to the top? The issue is the child page will remain in the same spot of the page, because the iframe has a lot of height larger than the parent page.
请注意:父页面和子页面位于不同的子域中.
Please note: the parent and child pages are on different sub domains.
我创建了一个演示来展示这一点:http://www.apus.edu/_test/iframe/index.htm
I created a demo to show this:http://www.apus.edu/_test/iframe/index.htm
推荐答案
诀窍是将以下 onload="window.parent.parent.scrollTo(0,0)"
附加到 onload="window.parent.parent.scrollTo(0,0)"
code>iframe 就可以了!
The trick is to append the following onload="window.parent.parent.scrollTo(0,0)"
to the iframe
and that should do it!
这篇关于在 iframe 中单击子页面时,如何将父页面滚动到顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!