简体   繁体   中英

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. Some of my JS functions require instantly scrolling to the top of the page, which works fine in a desktop browser. 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.

I've tried everything I can think of: scrollTop = 0 , x.scrollTo(0,0) , as well as jQuery's animate({ scrollTop: 0 }) and scrollTop() . All of these were attempted with a wide variety of selectors (an applicable div, window , body , html , document , parent.document , etc).

The answer in this thread also seems to be outdated in newer versions of iOS.

Any help or suggestions to get this running would be appreciated!

There's an app a css property for that:

/* 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]', '*');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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