get the actual with and height of a document's content

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>
 
T

Thomas 'PointedEars' Lahn

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.

No, you do not want that.

However, you will recognize that even if the displayed resource is not
markup, HTML markup is used by browsers to display the content. So there
is always a `html' and a `body' element.
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?

<URL:http://www.quirksmode.org/viewport/compatibility.html>


PointedEars
 
O

optimistx

Thomas 'PointedEars' Lahn said:
No, you do not want that.
....

I think I wanted to dimension an iframe to accommodate the contents without
scrollbars. But alas, somebody knows, that I did not want that... :)

I want to draw a circle with three corners. I want that.
 
B

blueapricot416

Another successful usenet posting! ;)

Three cheers to anonymous help and the power of newsgroups!
 
J

juergen.riemer

I think I wanted to dimension an iframe to accommodate the contents without
scrollbars. But alas, somebody knows, that I did not want that... :)

Your are right, I do not want to but was given a task by my supervisor.
Scrollbars are not an option for this application (eventhough it is B2B
with a defined system there would be other options I'd like more)
I want to draw a circle with three corners. I want that.

Really do you want to? This would be an interesting academic question,
same might go with my initial problem..

Thanks in any case

greetz

mord
 
J

juergen.riemer

As for me wanting to do this.. I was given the order to find a solution
(for an intranet app, defined system).

To get the according height is not of a problem, but how to get
information on the width? Any idea more elegant than the existing?

BTW: Thanks for the link, PPK is in my bookmarks for years though ;)

greetz

mord
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top