Anchor tags and iFrames

    Date: 12/11/06 (Web Development)    Keywords: php, html, java, google

    Hey guys,


    My question is about iFrames. But let me backtrack and tell you about the kind of thing I'm trying to implement.

    I'm actually using an iFrame to embed a blog to an ordinary HTML page. When the user clicks on "read comments," the php code fetches the site_url + #anchor. Ok? Now, this was fine in theory until I tried it out, and turns out that using URL + anchor in an iframe scrolled the PARENT window down, as well as the iFrame.

    So, I googled around and found this script, which uses offSetTop to determine how many pixels the element is off the top, and then sets the scroller to that location thanks to scrollTop. This looks like just what I need actually, and with some modifications, it might work, but when it comes down to it, this script displays navigation buttons on the parent page (mine shouldn't do that) and also the buttons are generated by the iframe.


    < script type="text/javascript" >
    < !--

    function goAnchor(id){
    anchorPos = window.frames['anchor_iframe'].document.getElementById(id).offsetTop;
    window.frames['anchor_iframe'].document.body.scrollTop = anchorPos;

    }

    // -- >

    As a way of thinking myself out of this box, I figured that I could perhaps...make PHP embed the scrollTop value in the URL...(which is probably not feasible since scrollTop is DOM property, not HTML) and my second idea is using PHP to put out a few lines of JavaScript that scrolls the window after it has been loaded, and while I sense this might work, I wonder if there is a standard way of getting around the problem, which is the unwanted scrolling of the parent window to the anchor tag of the embedded iFrame.

    Makes sense?

    Sorry I can't provide a link to this implementation, since I'm working on it locally and can't take it live right now.

    Oh...plus..do you know...if there is any way of fetching variable values from inside an iframe for use by the parent tag? Not DOM properties, mind you, but like some JS variable.

    Source: http://community.livejournal.com/webdev/375424.html

« any geo-targeting... || Quiz? »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home