Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2004
    Location
    near the only active volcano in the continental US
    Posts
    409
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Setting a document dimension

    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.

    Code:
    <html>
    
    <head>
    
    <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>')
    }
    }
    
    </script>
    
    </head>
    
    <body bgcolor="#ffffff" topmargin="0" leftmargin="0" bgproperties="fixed" background="newdesertbg2.jpg" onLoad="setwindow()">
    </body>
    
    </html>

  • #2
    Regular Coder
    Join Date
    Aug 2005
    Location
    Toronto, ON, Canada
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.)
    rm -f /

  • #3
    Regular Coder
    Join Date
    Nov 2004
    Location
    near the only active volcano in the continental US
    Posts
    409
    Thanks
    6
    Thanked 2 Times in 2 Posts
    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.
    Last edited by greasonwolfe; 10-19-2005 at 07:24 PM.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •