Scroll a cross-domain child iframe?

iframe, javascript

Solution

One approach to this is to set a negative top on the iframe, then set it taller than you need it.

For example, if you want to display it scrolled to `100px`, then set `top:-100px` and add 100px to the height.

Then all you need is for the top part of the iframe to be hidden, e.g. off the top of the screen or underneath other elements (using z-index).

This would probably be combined with `scrolling="no"` on the iframe element.

Problem

Is it possible to load a cross domain child iframe and scroll it to a certain section? Say, for instance, I wanted to reference a question on Stack Overflow, and using JavaScript, scroll it to the particular part of the page where the question is, and maybe overlay a highlight, or something. My hack would be to load the iframe with a huge height, like really really tall, and then scroll it by just moving the position. That sucks though, is there a better way?

Original source