views:

342

answers:

1

I need to insert an applet into a table-row and get that table-row's height to dynamically resize according to the browser's window size. If I put fixed values for width & height in the td-tag, it shows the applet fine, but I need to be able to resize this according to the client's size capabilities, so using fixed sizes is not the answer.

The snippet below should illustrate where my problem lies:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd"&gt;

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JavaAppletTest </title>
    </head>

    <body bgcolor="#6f6f6f" >
     <table border="0" cellspacing="0" cellpadding="0" width="100%" >
      <tr valign="top">
       <td><img src="images/myheader.jpg" alt="myheader.jpg"></td>
       <td><img src="images/mylogo.jpg" alt="mylogo.jpg"></td>
      </tr>
      <tr >
       <td colspan="2" >
        <object codetype="application/java"
              classid="java:applets.MyTestApplet.class">
         <param name="codebase" value="." >
         <param name="archive" value="MyTestApplet.jar" >
         <param name="code" value="applets.MyTestApplet" >
        </object>
       </td>
      </tr>
     </table>
    </body>
</html>

What do I need to do to make the row-dimensions dynamic?

[edit] jitter's answer indicates a possible solution. I also need to adjust the relevant sizes when the user resizes the window: what event & how do I do that?

+1  A: 

I suggest using javascript to write the object/embed tag and calculating the size dynamically.

This should do the trick basically but be aware of the fact that getting the correct width and size can be tricky. I refer you to Finding the size of the browser window.

...
<head>
...
  <script type="text/javascript">
    window.onresize = function(event) {
      document.getElementById('myobject_tag').height = window.innerHeight;
      document.getElementById('myobject_tag').width = window.innerWidth;
    }
  </script>
</head>
...
<body bgcolor="#6f6f6f">
  <table border="0" cellspacing="0" cellpadding="0" width="100%">
    <tr valign="top">
      <td><img src="images/myheader.jpg" alt="myheader.jpg"></td>
      <td><img src="images/mylogo.jpg" alt="mylogo.jpg"></td>
    </tr>
    <script type="text/javascript">
      var height = window.innerHeight;
      var width = window.innerWidth;
      document.write(
        '<tr><td colspan="2"><object id="myobject_tag"\n' +
        'codetype="application/java"\n' +
        'classid="java:applets.MyTestApplet.class"\n' +
        'width="' + width + '"\n' +
        'height="' + height + '"\n>' +
        '<param name="codebase" value=".">\n' +
        '<param name="archive" value="MyTestApplet.jar">\n' +
        '<param name="code" value="applets.MyTestApplet">\n' +
        '</object></td></tr>'
      );
    </script>
  </table>
...
jitter
Thanks, your script works 100% (on firefox). Now I need to just adjust it to make the table fit.
slashmais
slashmais
enhanced code snippet. note javascript in head and the id tag in the object tag
jitter
Thanks - exactly what I needed. (Got the table-size fitting nicely in the meantime) :-)
slashmais