/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Dynamically-loaded content results in incorrect page length in IE and Firefox

[B]FINAL UPDATE: The problems described in this message were caused by two issues. I will describe them here so it may help others in the future.

  • 1.

    Contrary to various web articles I read, the “height: auto” CSS style attribute can NOT be assumed to be assigned to DIVs by default. In my case, Firefox didn’t assign the “auto” setting by default to my “content” div while IE did. I had to explicitly set it in my style sheet for it to work as expected in both browsers.

  • 2.

    The [URL=http://www.deluxe-menu.com]Deluxe-Menu component[/URL] that I’m using will adjust its submenu positions correctly if it is encapsulated in an absolutely-positioned div, but ONLY IF THE ENCAPSULATING DIV’S “POSITION: ABSOLUTE” STYLE ATTRIBUTE IS INLINE. I originally specified the style in my style sheet. Once I moved it to my div declaration, i.e., <div id=”SiteMenu” style=”position: absolute”>, the submenus were positioned correctly. The previously-incorrect submenu positioning was what was causing the page length to be extended beyond the expected bottom of the page, as described below.[/B]

  • ==== Original post follows ====

    Hello all,

    First, thanks in advance for any advice offered!

    I have a site I’m developing ([URL=http://www.tommyb.com/gsc/]http://www.tommyb.com/gsc/[/URL]) that uses a hidden iFrame to load page content. It is hidden via the following CSS style:

    [CODE]#SiteBuffer
    {
    position: absolute;
    visibility: hidden;
    display: none;
    left: 0;
    top: 0;
    }[/CODE]

    The contents are copied to a “content” div on the main page via InnerHTML once they are loaded into the hidden iFrame. This div doesn’t have any special properties as far as absolute positioning or sizing. Its style is:

    [CODE]body
    {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 8pt;
    color: #F3EC67;
    background-color: #000080;
    margin:5;
    padding: 0;
    }
    #SiteContent
    {
    color: #000080;
    background-color: #D6BF5B;
    }[/CODE]

    I have also encapsulated the site menu in an absolutely-positioned div. I reposition it as users scroll up and down the page so it will stay in view. Here’s the CSS style for it:

    [CODE]#SiteMenu
    {
    position: absolute;
    left: 6;
    top: 100;
    z-index: 100;
    }[/CODE]

    Here’s the div positioning Javascript code:

    [CODE]function adjustMenus()
    {
    document.resetMenuPos = false;
    var startY = findPosY(getElement(‘SiteContent’)); //set y offset of bar in pixels
    var ns = (navigator.appName.indexOf(“Netscape”) != -1) || window.opera;

    function ml(id)
    {
    var el = document.getElementById(id);
    el.style.visibility = “visible”;
    if (document.layers)
    el.style = el;
    el.sP=function(y) {this.style.top = y + “px”;};
    el.y = startY;
    return el;
    }

    window.stayTop = function()
    {
    ContentDiv = getElement(‘SiteContent’);
    startY = findPosY(ContentDiv); //set y offset of bar in pixels
    pY = (ns ? pageYOffset : getIEDocBody().scrollTop) + 5;
    ContentBottom = startY + ContentDiv.offsetHeight;

    ftlObj.y += ((pY > startY ? pY : startY) – ftlObj.y) / 5;
    // Ensure new position is inside the top and bottom positions of our content div
    if (ftlObj.y < startY || document.resetMenuPos == true)
    ftlObj.y = startY;
    else if (ftlObj.y + ftlObj.offsetHeight > ContentBottom)
    ftlObj.y = ContentBottom – ftlObj.offsetHeight;
    document.resetMenuPos = false;
    ftlObj.sP(ftlObj.y);
    setTimeout(“stayTop()”, 15);
    }

    ftlObj = ml(“SiteMenu”);
    stayTop();
    }[/CODE]

    [B]Here’s the problem:[/B] The page length isn’t always correctly updated across page loads if you have scrolled down to the bottom of the page before clicking a menu link. It always works correctly if you are at the top of the page when you select a menu item.

    It also works correctly from the bottom of the page if the new page content is greater than the previous content. The “content” div shows all the newly-loaded content and the scroll range is correct.

    However, the page scrolling range will extend beyond the bottom of the page if the new page content is less than the previous content, but only if you selected the menu link while viewing the bottom of the page.

    [B]TO TEST THE PROBLEM:[/B] Please alternate between clicking the “This Week at GSC” and “About GSC” links. The “This Week” link has approximately twice as much content as the “About” link. [I]The problem should be apparent after scrolling to the bottom of the default “This Week” page and selecting the “About” link.[/I]

    Some additional info:

  • The behavior is consistent across both IE and Firefox.

  • If you select all of the page content, nothing is selected below the page footer, which suggests there aren’t any extraneous carriage returns or spaces causing the page to be incorrectly extended.

  • I have examined the page content with Firefox’s DOM Inspector once it is incorrectly extended. None of the div coordinates exceed the correct page bottom value.

  • Pressing the “End” key multiple times causes the page to scroll further down once the page is incorrectly extended.

  • I attempted to fix this by repositioning both the scroll position back to the top of the page (via window.scrollTo(0,0)) and the menu prior to loading the new content into the hidden iFrame. These changes had no effect on the problem.

  • Again, thanks for any help on this. I’ve spent about 6 hours trying to figure out the problem and I’m stumped!

    Tom Baggett

    [B]UPDATE:[/B] I did notice one discrepancy between IE and Firefox behavior. In IE, the “content” div is resized when new content is loaded if you are at the top of the page when you click the link. Firefox does not resize the div, resulting in it looking like there is a lot of blank lines in the content div.

    to post a comment
    JavaScript

    4 Comments(s)

    Copy linkTweet thisAlerts:
    @phpnoviceJun 05.2006 — There is an error being generated both at page load and with each click of those two menu entries.
    Copy linkTweet thisAlerts:
    @tbaggettauthorJun 05.2006 — Sorry, I added a call to document.recalc(true) to see if it would fix the problem. It is now removed.

    The other problems (incomplete background color, font size info) reported in Firefox's JS console are due to the menu component I'm using ([URL=http://www.deluxe-menu.com]http://www.deluxe-menu.com[/URL]).

    Tom
    Copy linkTweet thisAlerts:
    @tbaggettauthorJun 05.2006 — Thanks for taking a look at my problem. I now think the menu component I'm using may be part of the problem. I will resolve issues with it first and see if the problem I described goes away.

    Tom
    Copy linkTweet thisAlerts:
    @tbaggettauthorJun 07.2006 — I've determined the sources of the problem and have updated the original post to aid others in the future.

    Tom
    ×

    Success!

    Help @tbaggett spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.1,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...