如何在iframe中单击子页面时将父页面滚动到顶部? [英] How do I Scroll parent page to top when child page is click within iframe?

查看:86
本文介绍了如何在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆