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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Here's the code you require.


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



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);


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.  


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mkdebontAuthor Commented:

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.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.