0

I have an HTML document with an iframe in it. Now, if you click a certain button/link in the iframe, I want the parent document to scroll back to the top.

I'm not sure how to make that work. When I put an anchor at the top of the parent document, and have the button do something like window.parent.location = '#anchorname';, then the browser opens the iframe document itself, having the parent one vanish.

pb2q
  • 58,613
  • 19
  • 146
  • 147
Galbota
  • 63
  • 9

1 Answers1

0

First of all, I suggest the usage of JQuery scrollTop (see here) to scroll on top. This is not enough, however, you need to call your function from the page in the iFrame, so, supposing that your function which scrolls your document is called 'foo', you can call your function from the page in the iFrame this way:

window.parent.foo();

Hope this helps.

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • Hmmm, I use normally Dojo. I now made the iFrame button call a function in the parent docment (which reads "window.location = #top" and has an a-tag with name = "top"), but that still doesn't work. When I click on the button, the browser just opens the iframe document. – Galbota Jun 12 '12 at 11:27
  • That's the normal behavior of a link. If you click on it, the page will navigate to the referenced location. You can prevent the normal behavior, read more here: http://stackoverflow.com/questions/1357118/event-preventdefault-vs-return-false – Lajos Arpad Jun 12 '12 at 12:12