Hallo, I have a <div> with a table and I would like to be posed exactly in the center of the window. Different user have different screen configuration. How can I know where exactly the center of the window is, and pose the div there? Thanks.
Well im not sure how you find the center point with javascrict, but this method works fine to centre a div Just assign this styles to the div container: .c1 { overflow:auto; position:absolute; left: 50%; top: 50%; width: 200px; height: 200px; margin-top: -100px; margin-left: -100px; } HTML: The margin left needs to be half of the width, and the margin top needs to be half of the height, but then a negative sign added to it
Hi Betty, after recently spent time on a centered popup, I'm sure you can safely borrow some parts of this code to make it work for what you want. <!--Advertise PopUp --> function preview2(URL) { var previewWindow; var width = screen.width; var height = screen.height; var boxwidth = '368'; var boxheight = '250'; var xpos = (width / 2) - (boxwidth / 2); var ypos = (height / 2) - (boxheight / 2); previewWindow = window.open(URL, 'preview', 'width='+boxwidth+',height='+boxheight+',left='+xpos+',top='+ypos+',resizable=no,scrollbars=yes,toolbar=no,location=no,status=no,menubar=no,copyhistory=no'); } Let me know if it's of ANY use. Regards, Rich. Code (markup):
Here's how I got it to work on IE awhile ago: <body onLoad="document.body.style.paddingTop=(Math.max(parseInt((document.body.clientHeight - document.getElementById('docMargins').offsetHeight) / 2), 0) + 'px');document.body.style.visibility='visible';" style="visibility:hidden"><div id="docMargins" style="border:1px solid black"> Code (markup):