I want to have a div in the centre of the screen without using tables, so I have decided to use JavaScript, however it works in IE and NS 4.7 but not NS 6. I have written 2 functions, one to get the div (getElement), and one to move it (centreDiv). Here they are:
And then in HTML I open the div then call the centreDiv function, thus:Code:function getElement(myID) { if(document.layers){ return document.layers[myID];} else if(document.all){ return document.all[myID].style;} else{ return document.getElementById(myID).style;} } function centreDiv(myDiv, divHeight, divWidth) { if (window.innerWidth) { var windowWidth = window.innerWidth var windowHeight = window.innerHeight } else if (document.all) { var windowWidth = document.body.clientWidth var windowHeight = document.body.clientHeight } else { var windowWidth = 0 var windowHeight = 0 } if (windowWidth > 0 && windowHeight > 0) { getElement(myDiv).top = parseInt((windowHeight / 2) - (divHeight / 2)); getElement(myDiv).left = parseInt((windowWidth / 2) - (divWidth / 2)); } }
The div is set to a width and height of 400 and 749 respectively in CSS. The div looks fine in both IE and NS however it is in the top left of the screen in NS 6 and centred in IE and NS 4.7.Code:<div class="backimage" id="mainPannel"> <script language="JavaScript" type="text/javascript"> <!-- centreDiv("mainPannel", 400, 749); //--> </script> </div>
Has anyone got any ideas?
Thanks in advance.




Bookmarks