Link to home
Start Free TrialLog in
Avatar of tbaseflug
tbaseflugFlag for United States of America

asked on

Force parent frame, from within iFrame to Scroll

Is there a way - from a JS event in my iFrame, to force the Parent Frame to Scroll to the top?
Avatar of Bane83
Bane83
Flag of Canada image

Only if the contents of the iframe and the parent are on the same domain.  There are security restrictions enforced on iframes which in most cases prevent you from accessing the iframe from the parent and vice versa.

Here's a bit of a discussion on the subject with a similar question to yours.  Also a bit of a solution for you provided you're using the same domain for both: http://bytes.com/forum/thread150689.html
DId you try parent.scroll(0,0)?
index1.htm
<p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p>
<p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p>
<p>test</p><p>test</p><p>test</p><p>test</p><p>test</p><p>test</p>
 
<iframe src="2.htm" height="200" width="300"></iframe>
 
-------------------------------------------------------------------
 
index2.htm (iframe)
 
<a href="javascript:void(0)" onclick="parent.scroll(0,0)">click</a>

Open in new window

Avatar of tbaseflug

ASKER

It will be cross-domain, but assuming that I can get access to the parents source code - is there any workaround from that perspecive?
Unfortunately for you, no.  If you try to access one document from the other (via the iframe) javascript will throw errors and not do anything else.
Is there a way - from within the iFrame - to force the iFrame to scroll up to the top of the iFrame or jump up to something like an anchor
ASKER CERTIFIED SOLUTION
Avatar of Bane83
Bane83
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial