473,757 Members | 8,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

code for freezing html header

7 New Member
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

Expand|Select|Wrap|Line Numbers
  1. var divContent = null;
  2. var divHeaderRow = null;
  3. var divHeaderColumn = null;
  4. var divHeaderRowColumn = null;
  5. var headerRowFirstColumn = null;
  6. var x;
  7. var y;
  8. var horizontal = false;
  9. var vertical = false;
  10. var browsername = null;
  11. // Copy table to top and to left
  12. function CreateScrollHeader(content, scrollHorizontal, scrollVertical)
  13. {
  14.     browsername = navigator.appName;
  15.     horizontal = scrollHorizontal;
  16.     vertical = scrollVertical;
  17.  
  18.     if (content != null)
  19.     {
  20.         divContent = content;
  21.         if (browsername == 'Netscape')
  22.         {
  23.             var headerRow = divContent.childNodes[1].childNodes[1].childNodes[1];
  24.             var headersecondrow =divContent.childNodes[1].childNodes[1].childNodes[2];
  25.             x = divContent.childNodes[1].offsetWidth;
  26.             y = divContent.childNodes[1].offsetHeight;
  27.         }
  28.         else
  29.         {
  30.             var headerRow = divContent.childNodes[0].childNodes[0].childNodes[0];
  31.             var headersecondrow =divContent.childNodes[0].childNodes[0].childNodes[1];
  32.             x = divContent.childNodes[0].offsetWidth;
  33.             y = divContent.childNodes[0].offsetHeight;        
  34.         }
  35.         divHeaderRow = divContent.cloneNode(true);        
  36.         if (horizontal)
  37.         {
  38.             divHeaderRow.style.height = headerRow.offsetHeight + headersecondrow.offsetHeight;
  39.             divHeaderRow.style.overflow = "hidden";
  40.  
  41.             divContent.parentNode.insertBefore(divHeaderRow, divContent);
  42.             if (browsername == 'Netscape')
  43.             {
  44.             divContent.childNodes[1].style.position = "absolute";
  45.             divContent.childNodes[1].style.top = "-" + (headerRow.offsetHeight + headersecondrow.offsetHeight) ;
  46.  
  47.             }
  48.             else
  49.             {
  50.             divContent.childNodes[0].style.position = "absolute";
  51.             divContent.childNodes[0].style.top = "-" + (headerRow.offsetHeight + headersecondrow.offsetHeight) ;
  52.             }
  53.             y = y - headerRow.offsetHeight;
  54.         }
  55.  
  56.         divHeaderRowColumn = divHeaderRow.cloneNode(true);    
  57.             if (browsername == 'Netscape')
  58.             {
  59.                     headerRowFirstColumn = headerRow.childNodes[1];
  60.             }
  61.             else
  62.             {
  63.                 headerRowFirstColumn = headerRow.childNodes[0];
  64.             }
  65.         divHeaderColumn = divContent.cloneNode(true);
  66.         divContent.style.position = "relative";
  67.  
  68.         if (vertical)
  69.         {
  70.             divContent.parentNode.insertBefore(divHeaderColumn, divContent);
  71.             divContent.style.left = headerRowFirstColumn.offsetWidth;
  72.             if (browsername == 'Netscape')
  73.             {
  74.             divContent.childNodes[1].style.position = "absolute";
  75.             divContent.childNodes[1].style.left = "-" + headerRowFirstColumn.offsetWidth;
  76.             }
  77.             else
  78.             {
  79.             divContent.childNodes[0].style.position = "absolute";
  80.             divContent.childNodes[0].style.left = "-" + headerRowFirstColumn.offsetWidth;
  81.             }
  82.         }
  83.         else
  84.         {
  85.             divContent.style.left = 0;
  86.         }
  87.  
  88.         if (vertical)
  89.         {
  90.             divHeaderColumn.style.width = headerRowFirstColumn.offsetWidth;
  91.             divHeaderColumn.style.overflow = "hidden";
  92.             divHeaderColumn.style.zIndex = "99";
  93.  
  94.             divHeaderColumn.style.position = "absolute";
  95.             divHeaderColumn.style.left = "0";
  96.             addScrollSynchronization(divHeaderColumn, divContent, "vertical");
  97.             x = x - headerRowFirstColumn.offsetWidth;
  98.         }
  99.  
  100.         if (horizontal)
  101.         {
  102.             if (vertical)
  103.             {
  104.                 divContent.parentNode.insertBefore(divHeaderRowColumn, divContent);
  105.             }
  106.             divHeaderRowColumn.style.position = "absolute";
  107.             divHeaderRowColumn.style.left = "0";
  108.             divHeaderRowColumn.style.top = "0";
  109.             divHeaderRowColumn.style.width = headerRowFirstColumn.offsetWidth;
  110.             divHeaderRowColumn.overflow = "hidden";
  111.             divHeaderRowColumn.style.zIndex = "100";
  112.             divHeaderRowColumn.style.backgroundColor = "#ffffff";
  113.  
  114.         }
  115.  
  116.         if (horizontal)
  117.         {
  118.             addScrollSynchronization(divHeaderRow, divContent, "horizontal");
  119.         }
  120.  
  121.         if (horizontal || vertical)
  122.         {
  123.             window.onresize = ResizeScrollArea;
  124.             ResizeScrollArea();
  125.         }
  126.     }
  127. }
  128.  
  129.  
  130. // Resize scroll area to window size.
  131. function ResizeScrollArea()
  132. {
  133.     var height = document.documentElement.clientHeight - 120;
  134.     if (!vertical)
  135.     {
  136.         height -= divHeaderRow.offsetHeight;
  137.     }
  138.     var width = document.documentElement.clientWidth - 50;
  139.     if (!horizontal)
  140.     {
  141.         width -= divHeaderColumn.offsetWidth;
  142.     }
  143.     var headerRowsWidth = 0;
  144.     if(browsername == 'Netscape')
  145.     {
  146.         divContent.childNodes[1].style.width = x;
  147.         divContent.childNodes[1].style.height = y;
  148.     }
  149.     else
  150.     {
  151.     divContent.childNodes[0].style.width = x;
  152.     divContent.childNodes[0].style.height = y;
  153.     }
  154.     if (divHeaderRowColumn != null)
  155.     {
  156.         headerRowsWidth = divHeaderRowColumn.offsetWidth;
  157.     }
  158.  
  159.     // width
  160.     if(browsername == 'Netscape')
  161.     {
  162.         if (divContent.childNodes[1].offsetWidth > width)
  163.         {
  164.             divContent.style.width = Math.max(width - headerRowsWidth, 0);
  165.             divContent.style.overflowX = "scroll";
  166.             divContent.style.overflowY = "auto";
  167.         }
  168.         else
  169.         {
  170.             divContent.style.width = x;
  171.             divContent.style.overflowX = "auto";
  172.             divContent.style.overflowY = "auto";
  173.         }
  174.     }
  175.     else
  176.     {
  177.         if (divContent.childNodes[0].offsetWidth > width)
  178.         {
  179.             divContent.style.width = Math.max(width - headerRowsWidth, 0);
  180.             divContent.style.overflowX = "scroll";
  181.             divContent.style.overflowY = "auto";
  182.         }
  183.         else
  184.         {
  185.             divContent.style.width = x;
  186.             divContent.style.overflowX = "auto";
  187.             divContent.style.overflowY = "auto";
  188.         }
  189.     }
  190.     if (divHeaderRow != null)
  191.     {
  192.         divHeaderRow.style.width = divContent.offsetWidth + headerRowsWidth;
  193.     }
  194.  
  195.     // height
  196.     if(browsername == 'Netscape')
  197.     {
  198.         if (divContent.childNodes[1].offsetHeight > height)
  199.         {
  200.             divContent.style.height = Math.max(height, 80);
  201.             divContent.style.overflowY = "scroll";
  202.         }
  203.         else
  204.         {
  205.             divContent.style.height = y;
  206.             divContent.style.overflowY = "hidden";
  207.         }
  208.      }
  209.      else
  210.      {
  211.         if (divContent.childNodes[0].offsetHeight > height)
  212.         {
  213.             divContent.style.height = Math.max(height, 80);
  214.             divContent.style.overflowY = "scroll";
  215.         }
  216.         else
  217.         {
  218.             divContent.style.height = y;
  219.             divContent.style.overflowY = "hidden";
  220.         }
  221.      }
  222.     if (divHeaderColumn != null)
  223.     {
  224.         divHeaderColumn.style.height = divContent.offsetHeight;
  225.     }
  226.  
  227.     // check scrollbars
  228.     if (divContent.style.overflowY == "scroll")
  229.     {
  230.         divContent.style.width = divContent.offsetWidth + 17;
  231.     }
  232.     if (divContent.style.overflowX == "scroll")
  233.     {
  234.         divContent.style.height = divContent.offsetHeight + 17;
  235.     }
  236.         if(browsername == 'Netscape')
  237.         {
  238.             divContent.parentNode.style.width = divContent.offsetWidth + headerRowsWidth;    
  239.         }
  240.         else
  241.         {
  242.             divContent.parentElement.style.width = divContent.offsetWidth + headerRowsWidth;
  243.         }
  244.  
  245. }
  246.  
  247. ********************************************************************************
  248. // Synchronize div elements when scrolling 
  249. // from http://webfx.eae.net/dhtml/syncscroll/syncscroll.html
  250. // ********************************************************************************
  251. // This is a function that returns a function that is used
  252. // in the event listener
  253. function getOnScrollFunction(oElement) {
  254.     return function () {
  255.         if (oElement._scrollSyncDirection == "horizontal" || oElement._scrollSyncDirection == "both")
  256.             oElement.scrollLeft = event.srcElement.scrollLeft;
  257.         if (oElement._scrollSyncDirection == "vertical" || oElement._scrollSyncDirection == "both")
  258.             oElement.scrollTop = event.srcElement.scrollTop;
  259.     };
  260.  
  261. }
  262.  
  263. // This function adds scroll syncronization for the fromElement to the toElement
  264. // this means that the fromElement will be updated when the toElement is scrolled
  265. function addScrollSynchronization(fromElement, toElement, direction) {
  266.     removeScrollSynchronization(fromElement);
  267.  
  268.     fromElement._syncScroll = getOnScrollFunction(fromElement);
  269.     fromElement._scrollSyncDirection = direction;
  270.     fromElement._syncTo = toElement;
  271.     if(browsername != 'Netscape')
  272.         {
  273.             toElement.attachEvent("onscroll", fromElement._syncScroll);
  274.         }
  275.     else
  276.         {
  277.             toElement.addEventListener("scroll", fromElement._syncScroll,true);
  278.         }
  279. }
  280.  
  281. // removes the scroll synchronization for an element
  282.     function removeScrollSynchronization(fromElement) {
  283.     if (fromElement._syncTo != null)
  284.         if(browsername != 'Netscape')
  285.         {
  286.             fromElement._syncTo.detachEvent("onscroll", fromElement._syncScroll);
  287.         }
  288.         else
  289.         {
  290.             fromElement._syncTo.removeEventListener("scroll", fromElement._syncScroll,true);
  291.         }
  292.  
  293.     fromElement._syncTo = null;
  294.     fromElement._syncScroll = null;
  295.     fromElement._scrollSyncDirection = null;
  296. }
  297.  
Thanks
Sep 5 '07 #1
3 2725
gits
5,390 Recognized Expert Moderator Expert
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
Sep 5 '07 #2
dmjpro
2,476 Top Contributor
Look, I told to see that solution.
I think you didn't see it.

Anyway, it will be.
Expand|Select|Wrap|Line Numbers
  1. style.width="50px"; //Not = 50 or -50 or something like that.
  2. //this is valid.
  3.  
Now try it and see what happens.
Good luck.

Kind regards,
Dmjpro.
Sep 5 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
Don't use browser detection. You're checking for "Netscape" and basing your code on that. Use object detection instead, e.g.
Expand|Select|Wrap|Line Numbers
  1. if (obj.addEventListener) {
See this link.
Sep 5 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
1637
by: David. E. Goble | last post by:
Hi all; I have the following files; index.html, sigsheader.js, sigsboby.js, smilesbody.js and smiles.js. The sourse is below. The page displays two manual slide shows... Each slideshow has a set of buttons. the top slideshow (the smiles work fine. How ever the sigs slideshow displays the pictures in the smiles section. *************** index.html ***************************** <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01...
9
1833
by: David. E. Goble | last post by:
Arrrh! some buttons work while others don't, but I can't see why. I have tried comparing the files that do work, with the ones that don't. But to no help. The funny thing is the parts that work have the same code, except different variables. (Note Javascript and htm code was writen by a c program, the code then run thru a html to js converter)
4
3699
by: Matt | last post by:
I have a web page that reads a dataset, populates a datagrid, and then launches Excel to display the results. I was able to format the results (font, background color ..) and even create a filter for the top header row, but I want to also freeze the panes. Does anyone know of a way to program the WorksheetOptions information? Below is a sample of what I would like the result to be. I got this result by freezing the panes in Excel and...
17
2712
by: tshad | last post by:
Many (if not most) have said that code-behind is best if working in teams - which does seem logical. How do you deal with the flow of the work? I have someone who is good at designing, but know nothing about ASP. He can build the design of the pages in HTML with tables, labels, textboxes etc. But then I would need to change them to ASP.net objects and write the code to make the page work (normally I do this as I go - can't do this...
6
1949
by: Steven K | last post by:
Hello, I am having a problem where my computer is freezing when I run a ASP.net project. It freezes in the debugger, or if I try to run it as localhost. I cannot even access the windows Taskbar, or anything. I have to power off my computer. It is a brand new machine, XP Pro, VS.NET 2003. Other Notes:
10
2014
by: MaRCeLO PeReiRA | last post by:
Hi All, After PostgreSQL freeze some times, I am moving from 7.3.4 to 7.4.1, trying to solve this problem. When the daemon get frozen, I can't even use psql to browse a database (as if the database was down for some reason, or the daemon is not running). In these cases, a "pg_ctl -D /var/db stop" followed by
2
1638
by: Job Lot | last post by:
Is there any way of freezing columns in Windows Forms Data Grid control? Thanks
7
2042
by: bearophileHUGS | last post by:
Most of my ideas seem usless or stupid, but I think expressing them here doesn't harm much. This is an idea for Py 3.0, because it's not backward compatible. Dicts and sets require immutable keys, like tuples or frozensets, but to me they look like a duplication. So the idea is to remove tuples and frozensets (and replace the few other uses of tuples with lists, like the % interpolation), and to add a freeze operation, to freeze lists,...
3
2007
by: asearle | last post by:
Hi everyone, I currently display XML data with XSLT which works fine (including some dynamic filtering with JavaScript). However, often the data which is returned is quite lengthy and, as the user scrolls down to look at the data, the header disappears off the top of the viewable portion of the browser. This is quite irritating as the header contains summing and title information which should remain in view. So my question here is...
0
9489
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9906
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3829
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.