table width

How can I get from javascript the width of a table.

I tried to do it but I didn't get it!!

How can I get it. Because I want to resize a pop-up screen to the width of the table.
mkdebontAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
boycey19Connect With a Mentor Commented:
Here's the code you require.

<html>
<head>
</head>
<body>

<table id="table1" width="100" height="100">

</table>

<script>
<!--

var width, height;
var browser_name = navigator.appName;
var version = parseInt(navigator.appVersion);

if(browser_name == "Microsoft Internet Explorer" && version >= 4)
{
  width = document.all.table1.width;
  height = document.all.table1.height;
}

if(browser_name == "Netscape" && version >= 4)
{
  width = document.table1.width;
  height = document.table1.height;
}

document.write("The dimensions of the table are " + width + "x" + height);

//-->
</script>
</body>
</html>


I tried this code and it works. I have included the browser sniffer because of the varitaion in the Document Object Model. Remember to use "id" instead of "name" in the table tag, this is so we can refrence it as a JScript Object.  

Boycey
0
 
mkdebontAuthor Commented:
Thanx,

I had the same script only in the table tag I had "name" instead of "id". I didn't find anyting in a javascript book, but it will works like this.


Martijn
http://www.thekitchen.nl
0
All Courses

From novice to tech pro — start learning today.