Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / [HTML] Do anybody know how to retrieve content height of an IFRAME?

Author
Message
Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 26th Jul 2009 01:25
Like the annoyingly long title reads.
I've googled around for quite a while, but only find people complaining about it or examples that instead seems to return the height of the master document / page (containing the iframe in question; I need to find out the height of the content within that iframe).

What I'm trying to do is to have a page section displayed within an iframe; this page can basically be any (dynamic) one from my site, so the frame needs to be resized accordingly on each update. I can achieve the actual change in height, but I cannot retrieve the actual value of the full height of the content of the frame.

(Why am I doing it in this fuzzy way you say? Well, basically because in this way I can have the header and navigation sections preloaded at all times + the navigation has multiple levels, which would be a hassle to retain if you had to reload the navigation pane for each page).

Grateful for any advice,
Rudolpho

Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 26th Jul 2009 01:40
You could use AJAX, and just replace the html in the page with the new content (It would also mean that you wouldn't have the nasty 3d border around it in IE)

The only other way I can think of is to loop through all the DOM elements in the iframe, and for each one find the position of the bottom, and find the furthest down the page.

NeX the Fairly Fast Ferret
20
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 26th Jul 2009 01:51
Slight problem. JavaScript doesn't have permissions to access data out of the page's domain, and neither does Flash. That means you can't read data from iframes from other sites.

Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 26th Jul 2009 16:16 Edited at: 26th Jul 2009 16:16
@Diggsey: What border?
<iframe ... border = 0 ... > will remove it in IE as far as I can see?

@Nex: That's not a problem as all contents are on the same domain.

I think I finally got it to work using this function


Naturally there are some compatibility issues in IE though...

Diggsey
19
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 26th Jul 2009 16:55 Edited at: 26th Jul 2009 16:57
@Rudolpho

This code:


Should create a border-less iframe.

In Firefox it works, in IE 6 it doesn't. (Including variation with border-style:none, etc.)

edit:
After some searching I found that if you set the 'border:0' style on the body of the page INSIDE the iframe, you can remove the border in IE

Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 26th Jul 2009 19:07
I see. Well, my (simpler and uglier) solution works well in both IE and FireFox at least

Nickydude
Retired Moderator
18
Years of Service
User Offline
Joined: 4th Nov 2006
Location: Look outside...
Posted: 27th Jul 2009 00:13 Edited at: 27th Jul 2009 00:14
Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 27th Jul 2009 00:28
Good point... well, I've got it to work now at least, so I guess I'll be happy with that for a while

Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 27th Jul 2009 04:58
Why use frames at all? If you're going the ajax route, just make a div to act as your body's container and change its source.

container.innerHTML = loadPage('bio.html');

Obviously, you'd need to write the loadPage function.

[url="http://dbcc.zimnox.com"][/url]

Login to post a reply

Server time is: 2025-06-08 01:45:45
Your offset time is: 2025-06-08 01:45:45