Scrolling parent page when remote content loads in iframe

末鹿安然 提交于 2020-01-07 04:33:27

问题


I'm working on a website that loads remote content (real estate property listings) in an iframe on the main page. The issue being that the frames are quite long, and the navigation between pages of listings (located within the remote content of the iframe) sits at the bottom. Hence, when the 'next' button is clicked, the next page loads but it's at the bottom of the content because the parent page is the one scrolling. So what I want to do is make the parent page jump to the top whenever new content is loaded in the iframe.

I've done a lot of looking around, but all the solutions I've found seem to be based on the assumption that the content within the iframe is local and accessible. I haven't got access to the content that is being loaded in my frame — it's entirely third-party.

The link to the website is: http://www.rogermcmillan.com.au If you click on the 'properties for sale' tab, scroll to the bottom, and then click 'next', you'll see that the page remains at the bottom when the new content has loaded.


回答1:


Put javascript like <iframe srcStuff onLoad="scrollMeUp();">

And in <head> following code:

function scrollMeUp() {
    window.scroll(0,0);
}

If that doesn't work try debugging with alert, check what does window refer to, is it iframe or parent, or this function might not work on all browser, but I am not sure about that.



来源:https://stackoverflow.com/questions/5411848/scrolling-parent-page-when-remote-content-loads-in-iframe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!