code for freezing html header

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dotcom
    New Member
    • Sep 2007
    • 7

    code for freezing html header

    hello,
    i am sending whole javascript code(it is for freezing html header)
    it works fine eith IE but not firefox scroll bar does not come

    [code=javascript]var divContent = null;
    var divHeaderRow = null;
    var divHeaderColumn = null;
    var divHeaderRowCol umn = null;
    var headerRowFirstC olumn = null;
    var x;
    var y;
    var horizontal = false;
    var vertical = false;
    var browsername = null;
    // Copy table to top and to left
    function CreateScrollHea der(content, scrollHorizonta l, scrollVertical)
    {
    browsername = navigator.appNa me;
    horizontal = scrollHorizonta l;
    vertical = scrollVertical;

    if (content != null)
    {
    divContent = content;
    if (browsername == 'Netscape')
    {
    var headerRow = divContent.chil dNodes[1].childNodes[1].childNodes[1];
    var headersecondrow =divContent.chi ldNodes[1].childNodes[1].childNodes[2];
    x = divContent.chil dNodes[1].offsetWidth;
    y = divContent.chil dNodes[1].offsetHeight;
    }
    else
    {
    var headerRow = divContent.chil dNodes[0].childNodes[0].childNodes[0];
    var headersecondrow =divContent.chi ldNodes[0].childNodes[0].childNodes[1];
    x = divContent.chil dNodes[0].offsetWidth;
    y = divContent.chil dNodes[0].offsetHeight;
    }
    divHeaderRow = divContent.clon eNode(true);
    if (horizontal)
    {
    divHeaderRow.st yle.height = headerRow.offse tHeight + headersecondrow .offsetHeight;
    divHeaderRow.st yle.overflow = "hidden";

    divContent.pare ntNode.insertBe fore(divHeaderR ow, divContent);
    if (browsername == 'Netscape')
    {
    divContent.chil dNodes[1].style.position = "absolute";
    divContent.chil dNodes[1].style.top = "-" + (headerRow.offs etHeight + headersecondrow .offsetHeight) ;

    }
    else
    {
    divContent.chil dNodes[0].style.position = "absolute";
    divContent.chil dNodes[0].style.top = "-" + (headerRow.offs etHeight + headersecondrow .offsetHeight) ;
    }
    y = y - headerRow.offse tHeight;
    }

    divHeaderRowCol umn = divHeaderRow.cl oneNode(true);
    if (browsername == 'Netscape')
    {
    headerRowFirstC olumn = headerRow.child Nodes[1];
    }
    else
    {
    headerRowFirstC olumn = headerRow.child Nodes[0];
    }
    divHeaderColumn = divContent.clon eNode(true);
    divContent.styl e.position = "relative";

    if (vertical)
    {
    divContent.pare ntNode.insertBe fore(divHeaderC olumn, divContent);
    divContent.styl e.left = headerRowFirstC olumn.offsetWid th;
    if (browsername == 'Netscape')
    {
    divContent.chil dNodes[1].style.position = "absolute";
    divContent.chil dNodes[1].style.left = "-" + headerRowFirstC olumn.offsetWid th;
    }
    else
    {
    divContent.chil dNodes[0].style.position = "absolute";
    divContent.chil dNodes[0].style.left = "-" + headerRowFirstC olumn.offsetWid th;
    }
    }
    else
    {
    divContent.styl e.left = 0;
    }

    if (vertical)
    {
    divHeaderColumn .style.width = headerRowFirstC olumn.offsetWid th;
    divHeaderColumn .style.overflow = "hidden";
    divHeaderColumn .style.zIndex = "99";

    divHeaderColumn .style.position = "absolute";
    divHeaderColumn .style.left = "0";
    addScrollSynchr onization(divHe aderColumn, divContent, "vertical") ;
    x = x - headerRowFirstC olumn.offsetWid th;
    }

    if (horizontal)
    {
    if (vertical)
    {
    divContent.pare ntNode.insertBe fore(divHeaderR owColumn, divContent);
    }
    divHeaderRowCol umn.style.posit ion = "absolute";
    divHeaderRowCol umn.style.left = "0";
    divHeaderRowCol umn.style.top = "0";
    divHeaderRowCol umn.style.width = headerRowFirstC olumn.offsetWid th;
    divHeaderRowCol umn.overflow = "hidden";
    divHeaderRowCol umn.style.zInde x = "100";
    divHeaderRowCol umn.style.backg roundColor = "#ffffff";

    }

    if (horizontal)
    {
    addScrollSynchr onization(divHe aderRow, divContent, "horizontal ");
    }

    if (horizontal || vertical)
    {
    window.onresize = ResizeScrollAre a;
    ResizeScrollAre a();
    }
    }
    }


    // Resize scroll area to window size.
    function ResizeScrollAre a()
    {
    var height = document.docume ntElement.clien tHeight - 120;
    if (!vertical)
    {
    height -= divHeaderRow.of fsetHeight;
    }
    var width = document.docume ntElement.clien tWidth - 50;
    if (!horizontal)
    {
    width -= divHeaderColumn .offsetWidth;
    }
    var headerRowsWidth = 0;
    if(browsername == 'Netscape')
    {
    divContent.chil dNodes[1].style.width = x;
    divContent.chil dNodes[1].style.height = y;
    }
    else
    {
    divContent.chil dNodes[0].style.width = x;
    divContent.chil dNodes[0].style.height = y;
    }
    if (divHeaderRowCo lumn != null)
    {
    headerRowsWidth = divHeaderRowCol umn.offsetWidth ;
    }

    // width
    if(browsername == 'Netscape')
    {
    if (divContent.chi ldNodes[1].offsetWidth > width)
    {
    divContent.styl e.width = Math.max(width - headerRowsWidth , 0);
    divContent.styl e.overflowX = "scroll";
    divContent.styl e.overflowY = "auto";
    }
    else
    {
    divContent.styl e.width = x;
    divContent.styl e.overflowX = "auto";
    divContent.styl e.overflowY = "auto";
    }
    }
    else
    {
    if (divContent.chi ldNodes[0].offsetWidth > width)
    {
    divContent.styl e.width = Math.max(width - headerRowsWidth , 0);
    divContent.styl e.overflowX = "scroll";
    divContent.styl e.overflowY = "auto";
    }
    else
    {
    divContent.styl e.width = x;
    divContent.styl e.overflowX = "auto";
    divContent.styl e.overflowY = "auto";
    }
    }
    if (divHeaderRow != null)
    {
    divHeaderRow.st yle.width = divContent.offs etWidth + headerRowsWidth ;
    }

    // height
    if(browsername == 'Netscape')
    {
    if (divContent.chi ldNodes[1].offsetHeight > height)
    {
    divContent.styl e.height = Math.max(height , 80);
    divContent.styl e.overflowY = "scroll";
    }
    else
    {
    divContent.styl e.height = y;
    divContent.styl e.overflowY = "hidden";
    }
    }
    else
    {
    if (divContent.chi ldNodes[0].offsetHeight > height)
    {
    divContent.styl e.height = Math.max(height , 80);
    divContent.styl e.overflowY = "scroll";
    }
    else
    {
    divContent.styl e.height = y;
    divContent.styl e.overflowY = "hidden";
    }
    }
    if (divHeaderColum n != null)
    {
    divHeaderColumn .style.height = divContent.offs etHeight;
    }

    // check scrollbars
    if (divContent.sty le.overflowY == "scroll")
    {
    divContent.styl e.width = divContent.offs etWidth + 17;
    }
    if (divContent.sty le.overflowX == "scroll")
    {
    divContent.styl e.height = divContent.offs etHeight + 17;
    }
    if(browsername == 'Netscape')
    {
    divContent.pare ntNode.style.wi dth = divContent.offs etWidth + headerRowsWidth ;
    }
    else
    {
    divContent.pare ntElement.style .width = divContent.offs etWidth + headerRowsWidth ;
    }

    }

    *************** *************** *************** *************** *************** *****
    // Synchronize div elements when scrolling
    // from http://webfx.eae.net/dhtml/syncscroll/syncscroll.html
    // *************** *************** *************** *************** *************** *****
    // This is a function that returns a function that is used
    // in the event listener
    function getOnScrollFunc tion(oElement) {
    return function () {
    if (oElement._scro llSyncDirection == "horizontal " || oElement._scrol lSyncDirection == "both")
    oElement.scroll Left = event.srcElemen t.scrollLeft;
    if (oElement._scro llSyncDirection == "vertical" || oElement._scrol lSyncDirection == "both")
    oElement.scroll Top = event.srcElemen t.scrollTop;
    };

    }

    // This function adds scroll syncronization for the fromElement to the toElement
    // this means that the fromElement will be updated when the toElement is scrolled
    function addScrollSynchr onization(fromE lement, toElement, direction) {
    removeScrollSyn chronization(fr omElement);

    fromElement._sy ncScroll = getOnScrollFunc tion(fromElemen t);
    fromElement._sc rollSyncDirecti on = direction;
    fromElement._sy ncTo = toElement;
    if(browsername != 'Netscape')
    {
    toElement.attac hEvent("onscrol l", fromElement._sy ncScroll);
    }
    else
    {
    toElement.addEv entListener("sc roll", fromElement._sy ncScroll,true);
    }
    }

    // removes the scroll synchronization for an element
    function removeScrollSyn chronization(fr omElement) {
    if (fromElement._s yncTo != null)
    if(browsername != 'Netscape')
    {
    fromElement._sy ncTo.detachEven t("onscroll", fromElement._sy ncScroll);
    }
    else
    {
    fromElement._sy ncTo.removeEven tListener("scro ll", fromElement._sy ncScroll,true);
    }

    fromElement._sy ncTo = null;
    fromElement._sy ncScroll = null;
    fromElement._sc rollSyncDirecti on = null;
    }
    [/CODE]

    Thanks
    Last edited by gits; Sep 5 '07, 08:32 AM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

    please use the code tags when posting code ... this is the last friendly note about that ... it helps the users to better read your code and it is a posting rule ... that all members has to follow ... read:

    How to Ask a Question

    kind regards

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Look, I told to see that solution.
      I think you didn't see it.

      Anyway, it will be.
      [code=javascript]
      style.width="50 px"; //Not = 50 or -50 or something like that.
      //this is valid.
      [/code]

      Now try it and see what happens.
      Good luck.

      Kind regards,
      Dmjpro.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Don't use browser detection. You're checking for "Netscape" and basing your code on that. Use object detection instead, e.g.
        [CODE=javascript]if (obj.addEventLi stener) {[/CODE] See this link.

        Comment

        Working...