How to scroll to top of a page with code that is within an Iframe that is within several divs

I've got some existing code.  What it needs to do is scroll to the top of the page when each new 'page' is navigated to - this is simply a matter of replacing the html within the Iframe, so can't do it on a body onload or something like that.  The current code calls some javascript when the navigation is done.  They try to do a window.scrollTo(0,0); and a window.parent.scrollTo(0,0);, but neither works because the code is so far down into the window - or at least that's what I think.  I think I need to access the div with id of top and then use scrollTo on it, but not sure.  Thanks for your help in advance.  Please see attached html to see the structure of this.  Let me know if you need more details.  Thanks, Faith

Current code in frame's javascript that doesn't work is this:

window.scrollTo(0,0);
if(window.parent!= null)
{
window.parent.scrollTo(0,0);
}
<HTML xmlns="http://www.w3.org/1999/xhtml">
<BODY id="ctl00_ctl00_ctl00_HtmlBody">
<FORM id="aspnetForm" name="aspnetForm" action="/go/myhealthcenter/symptomreview.aspx" method="post">
<A id="TOP" name="TOP"><DIV id="Global"><DIV id="MainBody"><DIV id="Content"><DIV class="ContentLeft"><DIV 
 
id="Article"><DIV id="ArticleBody"> 
<IFRAME class="MHCDemographicIframe" 
 
id="ctl00_ctl00_ctl00_BodyContentPlaceHolder_MainContentPlaceHolder_MainContentPlaceHolder_MHCFrame" 
 
src="https://blah.com/PatientPortal/english/ReviewOfSymptoms.aspx?UserName=faithern" frameBorder="0" width="630" 
 
height="1150"></IFRAME> </DIV></DIV></DIV></DIV></DIV></DIV></A></FORM></BODY></HTML>

Open in new window

faithernAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

faithernAuthor Commented:
The javascript I am referring to is within the Iframe's aspx page...
0
Lolly-InkCommented:
The code below which you use works fine.
Check whether the code actually gets called. Put an alert after it.

window.scrollTo(0,0);
if(window.parent!= null)
{
window.parent.scrollTo(0,0);
}

Open in new window

0
faithernAuthor Commented:
I don't need an alert - I am debugging the IE process and I can see that it gets called...but it does NOT work - the page does not get scrolled to the top.
0
faithernAuthor Commented:
I figured it out.  Added an anchor at the top of my frame, and used the following code:
document.getElementById('toptest').scrollIntoView(true);

Still can't access main page, but top of frame is pretty good.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.