/    Sign up×
Community /Pin to ProfileBookmark

Get remote document height in iFrame

I have a page with a remote (another domain) document in an iFrame.
Now i want to resize the iFrame to the remote document height so no scrollbars apear. Due too security issues this seems impossible. My programming skills are not that great.. and WebDeveloper.com is my last resort to find a solution to this problem.

I have a script wich works with local files, but not remote:

[CODE]// addept iframe height to content height
function getDocHeight(doc) {
alert(“getDocHeight called!”);
var docHt = 0, sh, oh;
if (doc.height) docHt = doc.height;
else if (doc.body) {
if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
if (sh && oh) docHt = Math.max(sh, oh);
}
return docHt;
}

function setIframeHeight(ifrm) {
alert(“setIframeHeight called!”);
var iframeWin = window.frames[ifrm];
var iframeEl = document.getElementById ? document.getElementById(ifrm): document.all ? document.all[ifrm]: null;
if ( iframeEl && iframeWin ) {
alert(iframeWin.document.scrollHeight);
iframeEl.style.height = “auto”; // helps resize (for some browsers) if new doc is shorter than previous
var docHt = getDocHeight(iframeWin.document);
if (docHt) iframeEl.style.height = docHt + 30 + “px”; // add to height to be sure it will all show
}
}[/CODE]

The function setIframeHeight(); was called from the iframe.document (local).
Now i’ve added an onload=”setIframeHeight(iframeId);” in my iframe tag.

Does anyone know how to make this work with remote documents?
NOTE: I have access to the remote document.

Thanks in advance!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@sNapauthorJan 30.2006 — There must be someone who knows a solution.. or who can tell me if it's even possible at all?

thanks.
Copy linkTweet thisAlerts:
@physicforMay 07.2007 — thank you for sharing your code

i search the internet to find some thing like this finally am using your code but within my domian

i try to use the following code


<input type=button onclick="alert( document.frames('irf1').document.body.scrollHeight);" value="get external page height">

<iframe src="http://www.303030.com" name=irf1 ></iframe>

it gives me access denied and it's appaer that browser put iframe pages in the restriction area so

i beleive that the followning link is helpfull for you

http://msdn2.microsoft.com/en-us/library/ms535258.aspx

thank you again for your code

yours

mohamed ali
Copy linkTweet thisAlerts:
@physicforMay 07.2007 — thank you for sharing your code

i search the internet to find some thing like this finally am using your code but within my domian

i try to use the following code


<input type=button onclick="alert( document.frames('irf1').document.body.scrollHeight);" value="get external page height">

<iframe src="http://www.303030.com" name=irf1 ></iframe>

it gives me access denied and it's appaer that browser put iframe pages in the restriction area so

i beleive that the followning link is helpfull for you

http://msdn2.microsoft.com/en-us/library/ms535258.aspx

thank you again for your code

yours

mohamed ali
×

Success!

Help @sNap 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...