Categories
Web Development

Preventing iFrame Jump on Refresh

Situation:
An iFrame in the body of a page. A link on the page changes the location, i.e. reloads the iFrame.

Problem:
Whenever the iFrame reloads, the page jumps to the top.

Solution:
Give the iFrame the following code:
In the head portion add a JavaScript function that sets the parent window's scrollTo position to the Y position on the page you wish the page to be in after the iframe loads (e.g. 0,0) if you want it to reload to the top. Then, set the iFrame's body element's onload attribute to call this positioning function.

If WordPress’ new annoying editor worked well, I could have posted the code but apparently I am too stupid to work it out. Plain HTML did not work…

Share
Share