can i lock the iframe scroll bar when I am trying to open another link?

Basically i have a page with couple of buttons and an iframe. Each button has a different property which onclick event i pass to the iframe location and the iframe reloads depending the value which i am passing. That works fine. My problem is that every time the iframe reloads, the scroll bar comes as the top of the page. Since my iframe has a long list, and iframe hight is relatively small, the users needs to scroll down to review the data. When the user press another button, the iframe scroll goes by default on the top of the page and the user needs to scroll down again. This is somewhat annoying. Do you have any suggestions?
Thanks in advance.
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.

use named anchors in your iFrame and append to url "www.iframe.html#top"

It's a little vague what you're items are in the iFrame but you can create a reference to any part of your iFrame page by simply giving a name to an anchor tag like this

<a name="middle"></a>

...the above example doesn't create a link to anywere, just allows you to reference that location of the page.  Then if you wanted to reference it with a link you would write

<a href="#middle">go to middle of page</a>

...the effect of the above link is that it redirects to the same page but appends the #middle to the end of the url, the '#' tells the browser to look for an anchor tag with a name of whatever string comes after the '#' if you wanted you could just append the #middle to a url from script.

Hope that does it for ya!


p.s. you can also use this with existing named anchor tags which also have a link to somewhere else, it will just put page at position of that anchor.

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
You can do what you are asking.  You can check the scroll position before you reload the page and then set it when the page is reloaded.  This requires a function in the main page to store the scroll positions (I'm saving and setting both X and Y scroll positions) and another function to set the scroll position of the newly loaded page.  The key then is to have the page you are loading call the function to reset the scroll position.  If you try to do this before the page is fully loaded it will not work, that's why the page in the frame has to call it.

Hope this helps,


Here's the code to go into the main page:

<script type=text/javascript>
var scrollX, scrollY;
function loadPage() {
  if (document.all) {  // IE
    if (!window.frames[0].document.documentElement.scrollLeft)
      scrollX = window.frames[0].document.body.scrollLeft;
      scrollX = window.frames[0].document.documentElement.scrollLeft;
    if (!window.frames[0].document.documentElement.scrollTop)
      scrollY = window.frames[0].document.body.scrollTop;
      scrollY = window.frames[0].document.documentElement.scrollTop;
  else  { // Mozilla
    scrollX = window.frames[0].pageXOffset;
    scrollY = window.frames[0].pageYOffset;

function setScroll() {


In the frame page add an onLoad event:
<body onload="parent.setScroll();" >

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

From novice to tech pro — start learning today.