简体   繁体   English

无法在iOS的iframe中滚动到页面顶部

[英]Unable to scroll to the top of a page inside an iframe on iOS

I have a page being accessed on an external site via an iframe. 我有一个页面可以通过iframe在外部网站上访问。 Some of my JS functions require instantly scrolling to the top of the page, which works fine in a desktop browser. 我的某些JS函数需要立即滚动到页面顶部,这在桌面浏览器中可以正常工作。 But in a browser on iOS, when my page attempts to scroll to the top of itself while inside the iframe, it just won't work. 但是在iOS上的浏览器中,当我的页面试图在iframe中滚动到自身顶部时,它将无法正常工作。

I've tried everything I can think of: scrollTop = 0 , x.scrollTo(0,0) , as well as jQuery's animate({ scrollTop: 0 }) and scrollTop() . 我已经尝试了所有我能想到的东西: scrollTop = 0x.scrollTo(0,0)以及jQuery的animate({ scrollTop: 0 })scrollTop() All of these were attempted with a wide variety of selectors (an applicable div, window , body , html , document , parent.document , etc). 所有这些尝试都通过各种各样的选择器进行了尝试(适用的div, windowbodyhtmldocumentparent.document等)。

The answer in this thread also seems to be outdated in newer versions of iOS. 在新版本的iOS中, 该线程的答案似乎也已过时。

Any help or suggestions to get this running would be appreciated! 任何帮助或建议使此运行将不胜感激!

There's an app a css property for that: 一个应用程序 具有CSS属性:

/* select it here */ {
    overflow: scroll;
}

Of course, you can can also contact the external site in question and ask them to add this: 当然,您也可以联系有问题的外部网站,并要求他们添加以下内容:

<script>
window.onmessage=function(x) { window.scrollTo((a=JSON.parse(x.data))[0], a[1]); }
</script>

This way, it can be done like so: 这样,它可以像这样完成:

x.postMessage('[0,0]', '*');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM