在iframe中单击子页面时,如何将父页面滚动到顶部?

时间:2022-08-24 23:26:15

I have the same problem than Evan here :

我在这里遇到的问题与埃文相同:

How do I Scroll parent page to top when child page is click within iframe?

如何在iframe中单击子页面时将父页面滚动到顶部?

But my iFrame and parent page don't have the same domain. So the browser does not allow this :

但我的iFrame和父页面没有相同的域名。所以浏览器不允许这样:

onload="window.parent.parent.scrollTo(0,0)"

Oh, and I have no access to the parent's code at all. any idea..?

哦,我根本无法访问父代码。任何的想法..?

1 个解决方案

#1


0  

Let's say we have page from d1.com as parent and d2.com in iframe.

假设我们有来自d1.com的页面作为父级和d2.com的iframe页面。

What you need is open invisible iframe inside iframe (url should be like d1.com/scrollUp.html) with code

你需要的是在iframe中打开不可见的iframe(url应该像d1.com/scrollUp.html)和代码

onload="window.parent.parent.scrollTo(0,0)"

#1


0  

Let's say we have page from d1.com as parent and d2.com in iframe.

假设我们有来自d1.com的页面作为父级和d2.com的iframe页面。

What you need is open invisible iframe inside iframe (url should be like d1.com/scrollUp.html) with code

你需要的是在iframe中打开不可见的iframe(url应该像d1.com/scrollUp.html)和代码

onload="window.parent.parent.scrollTo(0,0)"