473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Obtaining the width of a table-cell

I have been trying to do something which should be quite simple: write a
cross-browser script which, as part of its function, involves finding
what the displayed width of a table cell is.

After several hours of Googling and trying test pages, I'm baffled.

Lots of webpages claim that one uses OffsetWidth. However this does not
return the width: it appears to return width+padding+border. Microsoft's
own documentation claims that IE does indeed return the width in
standards mode, but I've tested it and it doesn't (at least for table
cells). Opera and Firefox appear in this respect to be bug-compatible
with IE.

The style.width property is useless unless the width has been set
explicitly on this element. Similarly for currentStyle["width"].

Firefox provides the decidedly baroque
document.defaultView.getComputedStyle(x, "").getPropertyValue("width")
which seems to work. Opera recognises it, but provides the same broken
result as OffsetWidth. IE does not support this method.

How can one get hold of this rather elementary piece of information in
browsers other than Firefox/Mozilla?

--
Stephen Poley
Jun 18 '06 #1
1 1611
No-one got any suggestions?
On Sun, 18 Jun 2006 08:49:14 +0200, Stephen Poley
<sb******************@xs4all.nl> wrote:
I have been trying to do something which should be quite simple: write a
cross-browser script which, as part of its function, involves finding
what the displayed width of a table cell is.

After several hours of Googling and trying test pages, I'm baffled.

Lots of webpages claim that one uses OffsetWidth. However this does not
return the width: it appears to return width+padding+border. Microsoft's
own documentation claims that IE does indeed return the width in
standards mode, but I've tested it and it doesn't (at least for table
cells). Opera and Firefox appear in this respect to be bug-compatible
with IE.

The style.width property is useless unless the width has been set
explicitly on this element. Similarly for currentStyle["width"].

Firefox provides the decidedly baroque
document.defaultView.getComputedStyle(x, "").getPropertyValue("width")
which seems to work. Opera recognises it, but provides the same broken
result as OffsetWidth. IE does not support this method.

How can one get hold of this rather elementary piece of information in
browsers other than Firefox/Mozilla?


--
Stephen Poley
Jun 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Sharlet | last post by:
I am having a problem here. I have an ASP page which displays different images according to the querystring and the images are all of different sizes. However, in some browsers the image...
1
by: Charlie | last post by:
Hi, I'm looking for a way to obtain the width of a string, either in actual inches/centimeters, or pixels will also work. Unfortunately this seems difficult as I'd like to keep things as close to...
0
by: Lennart Hoglund | last post by:
Uploading an Image to a Server using the method described in the Knowledge Base article Q315832, works fine and smoothly. Obtaining the Image Size using; ImageSize.Text = New...
2
by: gregl | last post by:
Anyone know how to obtain the true size of the html document's body? The control contains the size that the control was set to. The body object appears to contain the same size. That information...
3
by: Chris Beall | last post by:
OK, I know that for many browsers, window height and width can be obtained from: window.outerHeight and window.innerHeight window.outerWidth and window.innerWidth And I know that if those are...
0
by: javaguy | last post by:
I have a table I hide show/hide through a pair of divs. The show/hide part works fine in both Mozilla and MSIE. When switching between the hide and show versions the Mozilla browser keeps them in...
2
by: Stewart | last post by:
Originally posted in comp.lang.javascript: Newsgroups: comp.lang.javascript From: "Stewart" Date: 23 Aug 2005 02:50:04 -0700 Local: Tues, Aug 23 2005 10:50 am Subject: FireFox, RemoveChild,...
11
by: Norman L. DeForest | last post by:
Am I misunderstanding the CSS specifications or is Firefox (version 1.0.6) (and Opera) doing the wrong thing? It appears that Firefox 1.0.6 includes the border in width calculations for tables...
2
by: Charleees | last post by:
Hi all, I have a DataGrid with Template Columns..... There are LAbels,Linkbuttons in the Single Row.. I have to set the Constant Column width for those Template Columns in Grid... Wat...
10
by: magnesium | last post by:
I have this under-construction page, If you try and select the link coming from the bottom with your mouse, you'll notice, that before the actual link is selected, the td background will change. you...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.