J
juergen.riemer
Hi all,
I want to get the actual dimensions of a document's content, not the
body's width/height. I want to do this to be able to resize an iframe
element in which this document resides to exactly the dimensions of the
text/content of this source.
My quick hack would be the code below, but it seems to be somewhat
wild.. is there a more elegant way to solve this problem?
greetz
mord
----
<html>
<head>
<script>
onload = function(){
var oBodyContent = document.body.innerHTML;
var oWrapper = document.createElement("DIV");
oWrapper.style.position = "absolute";
oWrapper.style.top = "0px";
oWrapper.style.visibility = "hidden";
var oTable = document.createElement("TABLE");
var oTBody = document.createElement("TBODY");
var oTRow = document.createElement("TR");
var oTData = document.createElement("TD");
oTRow.appendChild(oTData);
oTBody.appendChild(oTRow);
oTable.appendChild(oTBody);
oWrapper.appendChild(oTable);
document.body.appendChild(oWrapper);
oTData.innerHTML = oBodyContent;
alert(oTable.offsetWidth+' '+oTable.offsetHeight);
oWrapper.parentNode.removeChild(oWrapper);
}
</script>
</head>
<body>
blafasel <br>
blafasel <br>
blafasel <br>
</body>
</html>
I want to get the actual dimensions of a document's content, not the
body's width/height. I want to do this to be able to resize an iframe
element in which this document resides to exactly the dimensions of the
text/content of this source.
My quick hack would be the code below, but it seems to be somewhat
wild.. is there a more elegant way to solve this problem?
greetz
mord
----
<html>
<head>
<script>
onload = function(){
var oBodyContent = document.body.innerHTML;
var oWrapper = document.createElement("DIV");
oWrapper.style.position = "absolute";
oWrapper.style.top = "0px";
oWrapper.style.visibility = "hidden";
var oTable = document.createElement("TABLE");
var oTBody = document.createElement("TBODY");
var oTRow = document.createElement("TR");
var oTData = document.createElement("TD");
oTRow.appendChild(oTData);
oTBody.appendChild(oTRow);
oTable.appendChild(oTBody);
oWrapper.appendChild(oTable);
document.body.appendChild(oWrapper);
oTData.innerHTML = oBodyContent;
alert(oTable.offsetWidth+' '+oTable.offsetHeight);
oWrapper.parentNode.removeChild(oWrapper);
}
</script>
</head>
<body>
blafasel <br>
blafasel <br>
blafasel <br>
</body>
</html>