如何在iframe中单击子页面时将父页面滚动到顶部? [英] How do I Scroll parent page to top when child page is click within iframe?
问题描述
当有人点击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)
附加到 iframe
,应该这样做!
The trick is to append the following onload="window.parent.parent.scrollTo(0,0)"
to the iframe
and that should do it!
这篇关于如何在iframe中单击子页面时将父页面滚动到顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!