#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    3
    Rep Power
    0

    Use Javascript variable in html


    Hi, I'm using this code to determine the window width and height of a visitor to my page, but after I have the values os winW and winH, how can I use them in a tag for setting a table width and height?

    Basically I have a table on my page that I would like to fit the window properly when someone visits my page, I'm just not sure how to use the values in my html after I got them from a javascript. Thanks

    Chris

    Code to find window height and width :

    var winW = 630, winH = 460;

    if (parseInt(navigator.appVersion)>3) {
    if (navigator.appName=="Netscape") {
    winW = window.innerWidth;
    winH = window.innerHeight;
    }
    if (navigator.appName.indexOf("Microsoft")!=-1) {
    winW = document.body.offsetWidth;
    winH = document.body.offsetHeight;
    }
    }

    document.write(
    "Window width = "+winW+"<br>"
    +"Window height = "+winH
    )
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    421
    Rep Power
    13
    I am pretty new to web coding myself, but I would assign the values to two hidden inputs (one for width and one for height) and then integrate PHP into your HTML for the tables and call those variables for the W and H. I know it would work, but im sure there is a better way to do it.
    hmmm...
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    Waterloo, ON
    Posts
    7
    Rep Power
    0
    put this where you want your code for the table height and width to go:

    <script language="JavaScript">
    document.write("<table width=\"" + winW + "\" .... ")
    </script>

    and so on.

IMN logo majestic logo threadwatch logo seochat tools logo