View Full Version : Setting a document dimension

10-19-2005, 11:24 AM
I am trying to govern a minimum body width for a document by checking the window width and then writing out a table to force body width through javascript if the window width is less than the amount I need. For instance, if I need the document to be 1200 pixels wide, but a visitor is using a 1024 resolution setting then the page will have a scroll bar at the bottom. However, if the visitor is using a resolution higher than 1200 the table is not written out and the page loads normally. Here is the code I tried and after testing it in what I knew was a smaller browser window, I am not getting the results I want. Am I using the document.body.clientWidth call wrong or could it be in the parseInt() that I have encountered the error. I get no javascript error warnings when opening the window so I am at a complete loss.



<script type="text/javascript">

var window_width=document.body.clientWidth

function setwindow()
if (parseInt(window_width)<1200)
document.write('<table border="0" cellpadding="0" cellspacing="0" border="1" bordercolor="#888888" width="1400" bgcolor="#000000"><tr><td height="10"><font face="arial" size="3" color="#333333">Just some miscelaneous stuff</font></td></tr></table>')



<body bgcolor="#ffffff" topmargin="0" leftmargin="0" bgproperties="fixed" background="newdesertbg2.jpg" onLoad="setwindow()">


10-19-2005, 04:21 PM
Just specify
<table width="1200" ...>
the browser is going to take care if windows width is less then 1200

(actually you should specify 1180 or something like that, depends of body margins, etc.)

10-19-2005, 08:21 PM
LOL, I was going to go into this whole big explaination of what I was trying to do, then I read your response once again and it sort of hit me out of the blue that there was really a simple solution to the problem. I am not sure if it is what you were suggesting or not, but instead of going through the whole script routine, I could just set that table in the body of the coding and it will force the minimum left-right dimensions on smaller browsers. Sometimes I think I subconsciously try to make things harder than they are.

Now the only problem I would have to deal with is making sure that the static element that floats along the right hand side of the document shows up where it is supposed to be rather than blocking content. I will try to come up with a little image for it in a bit to better demonstrate what I am trying to do.

10-20-2005, 12:09 AM
Just remember that WebTV has a fixed width of 544 pixels and that the width of mobile phone screens is even smaller and that none of them allow a horizontal scroll.