Scrolling parent page when remote content loads in

2019-09-08 07:25发布

问题:

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.