Daily Archives: 01/06/2014

How to make “scrollIntoView” apply to IFRAME only

Let’s say you have a really long HTML page with scrollbars, for the sake of argument something like this:

<div>aaaa</div>
<div>aaaa</div>
<div>aaaa</div>
...more content...
<div id="xB">bbbb</div>
<div>aaaa</div>
<div>aaaa</div>
<div>aaaa</div>
...much more content...

And somewhere, perhaps on pageload, you want to make sure that highlighted element is visible to the user, so to scroll it into view you execute

document.getElementById("xB").scrollIntoView();

And it works fine and well – the needed element is automatically displayed on top of the page. But what if this page is in an IFRAME and the parent page has a large scrollable content of it’s own:
Continue reading →