Harry said:
I have an html table with width 100%, one row, fixed-sized cells.
I suppose you mean that every cell has a same fixed number of pixels.
I would like to find out using javascript the maximal number of
cells possible in the row.
This can't be known from the table itself; because 100% is always
relative to the parent element. E.g. suppose that you have a div of
80px width, a table of 100% width in it, and your cells must be 20px,
then you can have maximum 4 cells.
If you want to take the width of the browser window, then you could
do:
var winWidth, winHeight, d=document;
if (typeof window.innerWidth!='undefined') {
winWidth = window.innerWidth
} else {
if (d.documentElement &&
typeof d.documentElement.clientWidth!='undefined' &&
d.documentElement.clientWidth!=0) {
winWidth = d.documentElement.clientWidth
} else {
if (d.body &&
typeof d.body.clientWidth!='undefined') {
winWidth = d.body.clientWidth
}
}
}
var cell_width = 50 // fill in your cell pixels here
var max_cells = Math.floor(winWidth/cell_width)
document.write('You have room for max ' + max_cells + ' cells')
The solution (if one exists) needs to be cross-browser.
Okay.
Hope this helps,