Iframe Manipulation

Discussion in 'JavaScript' started by Hyphen, May 16, 2009.

  1. #1
    I am looking for a way to load an iframe pre-scrolled to a point in the page. Is there a way to do this?
     
    Hyphen, May 16, 2009 IP
  2. yoavmatchulsky

    yoavmatchulsky Member

    Messages:
    57
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    48
    #2
    in HTML:
    edit page.html and put an anchor in the middle (<a name="my_anchor"></a> )
    now the src of the iframe can be http://yoursite.com/page.html#my_anchor and it will jump to the anchor.

    in JS:
    calculate offsets of the page and other stuff and use window.scrollTo (or other compatible function) on load.


    in the HTML, you'll have to own the page. in JS, you can use your parent frame (browser) to control the iframe, so you can scrollTo on any page (haven't tried, but sounds like a plan)
     
    yoavmatchulsky, May 17, 2009 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #3
    Just to clarify - "id" should be used instead of "name" for the HTML solution. The "name" attribute is deprecated, and shouldn't be used. The rest will be exactly the same.
     
    PoPSiCLe, May 17, 2009 IP
  4. JavaScriptBank.com

    JavaScriptBank.com Peon

    Messages:
    141
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    JavaScriptBank.com, May 17, 2009 IP
  5. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #5
    I think you may only be able to do this if the page within the iframe is yours. I don't think a browser will allow you to change anything if the page is in a remote location.
     
    camjohnson95, May 18, 2009 IP