Why does my page scroll down when the iframe loads to an anchor point?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cvermar
    New Member
    • Aug 2010
    • 2

    Why does my page scroll down when the iframe loads to an anchor point?

    Hi, I'm new here.

    I'm teaching my self to write a web site to help my sister's new business. It's in a three column format.

    I put an small iframe on the main page's right column to show her blog, and I put in an anchor point (#iframe_target ) in the blog so that the iframe shows the beginning of the content of the blog rather than the top left corner:
    Code:
    <iframe  
    src="http://DOMAIN.blogspot.com#iframe_target" width="215" height="287"><p>Your browser does not support iframes.</p></iframe>
    Once I added this I now get that the whole webpage loads, then as soon as the iframe content loads, it scrolls up (about the same amount as the iframe content scrolls up, I think, but haven't verified).

    Can anyone explain what is happening? And better yet, give me idea how to fix either the initial problem (load the iframe content to the specific part of the webpage I want to show) or the subsequent problem (page scrolls up when iframe content loads)

    I have one fix, which is to use the following function
    Code:
    function jumpScroll() {
       	window.scroll(0,0); 
    }
    and then use it as follows:
    Code:
    <body onload="javascript:jumpScroll()" >
    But this means the page loads, scrolls up and scrolls down, and is just messy and inelegant.

    Any help will be greatly appreciated!
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    src="http://DOMAIN.blogspot .com#iframe_target"

    remove the bold text from your link. its causing the page to do down

    Comment

    • cvermar
      New Member
      • Aug 2010
      • 2

      #3
      Thanks, johny10151981.

      I know that adding #iframe_target caused the problem, but the reason I put it in is that I wanted the iframe to open not showing the top left corner of the blog (since the iframe is a small one on the side of the main page, and all you see is boring white space), and it makes no sense to me that if you load a webpage in an iframe at some anchor point then the main page somehow scrolls down.

      So if I remove it, I fix the second problem, but I'm back to my first one, which is to load the iframe content to the specific part of the blog I want to show rather than default top left corner. Is there an alternative way of doing that without making the main page scroll? Also, *why* does the main page scroll up like that?

      Comment

      • johny10151981
        Top Contributor
        • Jan 2010
        • 1059

        #4
        Now, i need to see the page. Without seeing cant help you :(

        Comment

        • sguggen
          New Member
          • Jan 2016
          • 1

          #5
          Thank you!!!!!

          Originally posted by johny10151981
          src="http://DOMAIN.blogspot .com#iframe_target"

          remove the bold text from your link. its causing the page to do down


          THANK YOU!!!! I'm not the initial asker but I've been looking for a solution to this for days and I just KNEW it was something really simple. You saved me life!!!

          Comment

          • jerrybustillo
            New Member
            • Feb 2026
            • 1

            #6
            I also have the same problem in using an iframe for a new blog. I use this code inside the iframe to fix it so it stays there every time -
            onload="window. parent.scrollTo (0,0);"

            Comment

            Working...