/    Sign up×
Community /Pin to ProfileBookmark

resizing iFrames

I’m trying to display a page inside an iFrame but I want the iFrame to dynamically change it’s height in relation to the height of the page within.

I have this bit of code in the iFrame Content page

[quote]

<script language=”JavaScript”>
parent.handleResponse(300);
</script>

[/quote]

and in the parent page

[quote]

<script type=”text/javascript”>
function handleResponse(msg) {
var x = document.getElementById(“myframe”);
x.height = msg;
}
</script>

[/quote]

Which passes the integer value of 300 to the function handleResponse and handleResponse then resizes the iFrame and everything works. But, I want to be able to change the 300 value to the height of the document which is proving a little more difficult.

something like body.document.height, but I know it’s not as simple as that. I’ve tried various different things like scrollHeight, client Height…and still no luck.

I’d appreciate any help you can offer.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@RabBellauthorDec 19.2007 — ** BUMP **

Any help on this is appreciated guys, and I do mean any help
Copy linkTweet thisAlerts:
@mrhooDec 19.2007 — You can only read the size of the document in the iframe if it is from the same domain as the page that contains the iframe.

[CODE]document.reframe= function(){
var who= document.getElementsByTagName('iframe')[0];
if(!who.contentWindow || !who.contentWindow.document){
return setTimeout(function(e){arguments.callee(e)},200);
}
var win= who.contentWindow; ;
var bod= win.document.body;
who.style.height= 1.2*bod.offsetHeight+'px';
who.onload= arguments.callee;
}
document.reframe();[/CODE]
×

Success!

Help @RabBell spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.9,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...