brett said:
That works nice. However, the above document should only be 200 wide.
It reports the browser doc width based on browser width, not the widest
tag element. I suppose I'm really looking for the widest "width"
attribute of any tag. That would give me the width based on what the
designer had in mind.
It can be tricky looking for width attributes. If a 100% width is
nested in a width=400, I might want to use your code to get the doc
width based on browser width. However, the true width is only 400.
The code only determines the internal width of the browser
window containing the document, it does not have any reference
to the width that the document requires or consumes.
I think you are getting too deep into HTML and CSS here.
JavaScript will help you find out whether elements have width
attributes defined, but that is only part of the story.
You must also consider width set by CSS - essentially, you have
to emulate the browser rendering engine. Can you deal with
relative & absolute positioned elements? Float left/right?
Display/visibility? Most browsers struggle to get it right.
If everyone used tables to layout their content, wouldn't life
be sooooo much simpler - friken' CSS-heads...
IIRC, most non-IE browsers will not report a width attribute if
none is specified, you have to use getComputedStyle - for those
browsers, getting the HTML established width is trivial (though
likely slow). However, IE seems to report attributes that
aren't set, as well as providing it's own version of a
getComputedStyle method too.
Finally, your job may be possible where the width is set
everywhere as pixels, but what about width as em, en or percent?
Do you know how to convert those to pixel widths?
Sorry to be such a pessimist! :-x