Alekz
10-08-2002, 03:04 PM
Hi,
Does anyone know a way to measure HTML content?
I mean, I get some HTML and want to evaluate its width and height after it has beed rendered by a browser?
I was able to do this using a hidden div and placing the HTML in a table cell, so I actually measure the surrounding table... The problem is that a table will not allways render the content conveniently. Like this:
1. create an empty layer (may keep it invisible)
2. put a table inside: <table border="0" cellspacing="0" cellpadding="0" id="measurer"><tr><td nowrap>HTML content here</td></tr></table>
3. Then only for the width:
- for Netscape4.x:
w = layer.document.width;
- for Netscape 6.x, 7 and I suppose Mozilla 1+
tbl = document.getElementById('measurer');
w = parseInt(document.defaultView.getComputedStyle(tbl, '').getPropertyValue("width"));
- for IE4
w = layer.scrollWidth;
- for IE5+
w = layer.document.getElementById('measurer').scrollWidth;
Well is there a way to do the same without using a table?
Alex
Does anyone know a way to measure HTML content?
I mean, I get some HTML and want to evaluate its width and height after it has beed rendered by a browser?
I was able to do this using a hidden div and placing the HTML in a table cell, so I actually measure the surrounding table... The problem is that a table will not allways render the content conveniently. Like this:
1. create an empty layer (may keep it invisible)
2. put a table inside: <table border="0" cellspacing="0" cellpadding="0" id="measurer"><tr><td nowrap>HTML content here</td></tr></table>
3. Then only for the width:
- for Netscape4.x:
w = layer.document.width;
- for Netscape 6.x, 7 and I suppose Mozilla 1+
tbl = document.getElementById('measurer');
w = parseInt(document.defaultView.getComputedStyle(tbl, '').getPropertyValue("width"));
- for IE4
w = layer.scrollWidth;
- for IE5+
w = layer.document.getElementById('measurer').scrollWidth;
Well is there a way to do the same without using a table?
Alex