By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,512 Members | 3,847 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,512 IT Pros & Developers. It's quick & easy.

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

P: n/a
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>

Apr 16 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
ju************@chello.at wrote:
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
Apr 16 '06 #2

P: n/a

"Thomas 'PointedEars' Lahn" <Po*********@web.de> kirjoitti viestissä
news:10*****************@PointedEars.de...
ju************@chello.at wrote:
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.

....

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.
Apr 16 '06 #3

P: n/a
Another successful usenet posting! ;)

Three cheers to anonymous help and the power of newsgroups!

Apr 16 '06 #4

P: n/a
> 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

Apr 17 '06 #5

P: n/a
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

Apr 17 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.