1

* Please note: cross-domain scenario *

I have an iframe which has no scrollbar, but much more taller than the browser window, so the vertical scrolling is done by the browser's main vertical scrollbar. However there is a disturbing feature of this: When the navigation done in scrolled down state the scroll is not reset to top in the parent.

I would like to reset this scroll to the init top state automatically when page navigation occurs in the iframe.

Thanks in advance.

UByVacy
  • 41
  • 4
g.pickardou
  • 32,346
  • 36
  • 123
  • 268

2 Answers2

2

If your iframe has a cross domain issue (pointing to somewhere other than your website) You can't:
error : Permission denied to access property 'document'

But if not, you can do it using this code. add this to scripts in page:

var myframe = window.frames[0].window;
myframe.onscroll = function(){if(myframe.scrollY == myframe.scrollMaxY){window.scrollTo(0,0);}};
//Thanks Diodeus!

Or you can select it by getElementById or other similars and give the reference to myframe variable. This triggers an event when you scroll down in the iframe and then scrolls the whole document up.

Community
  • 1
  • 1
UByVacy
  • 41
  • 4
0

You can hook an onload event to the iframe. It is one of the few hooks you can get in a cross-domain scenario.

document.getElementById("some_iframe").onload = function (){ window.scrollTo(0,0); }
Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176