cbresources — 2011-04-01T09:09:24-04:00 — #1
I've done a few searches and tried a few solutions but neither of them do what I want so I'm asking here to see if anyone knows of a way to automatically resize an iframe so that it extends to show 100% of the content without a scrollbar?
I'm using an Iframe to make a PHPBB forum that I have embed into a website I have built. I control the content for both so I can manipulate the HTML/CSS of both... I need the IFRAME to fully extend to the height of the forum index page, which I have been able to do using simple CSS styling but whenever you click a link in the forum to take you to another page, it keeps the same height instead of adopting the height of the new page so you lose half the content.
logic_ali — 2011-04-01T11:32:35-04:00 — #2
function setIframeHeight( iframeId ) /** IMPORTANT: All framed documents *must* have a DOCTYPE applied **/
var ifDoc, ifRef = document.getElementById( iframeId );
ifDoc = ifRef.contentWindow.document.documentElement;
catch( e )
ifDoc = ifRef.contentDocument.documentElement;
if( ifDoc )
ifRef.height = 1;
ifRef.height = ifDoc.scrollHeight;
/* For width resize, enable below. */
// ifRef.width = 1;
// ifRef.width = ifDoc.scrollWidth;
<iframe id = "myIframe" onload = "setIframeHeight( this.id )">
cbresources — 2011-04-03T11:02:29-04:00 — #3
Thanks you so much - that works perfectly!
z06_dave — 2011-08-15T18:57:36-04:00 — #4
I am trying this code on my site and it is not working. But yet if I pull up the site on my iphone, it works, I'm confused. I'm using ie 8.
logic_ali — 2011-08-15T19:17:18-04:00 — #5
And your URL is?
z06_dave — 2011-08-15T19:48:45-04:00 — #6
Thanks for trying to help....
Murray Motors of the Lehigh Valley | Used Car Dealership
logic_ali — 2011-08-15T20:00:45-04:00 — #7
That iframe displays a page from a different domain, therefore its properties cannot be accessed.
z06_dave — 2011-08-15T21:06:43-04:00 — #8
Ok, thanks again for the help...
Anyone now of any solution? I've searched everywhere...
vlbknl2 — 2011-08-15T23:44:50-04:00 — #9
Thank U very much, It's very necessary with me !!!. Can u run code to IFRAME Auto Width ?
logic_ali — 2011-08-16T07:28:55-04:00 — #10
Yes, just un-comment the lines indicated in the code. That means remove the //.
liligi — 2011-10-18T16:31:25-04:00 — #11
I'm using your method and have a problem I was wondering if you could help me through.
The good news, this is the only code I've found that resizes bigger and smaller depending on the iframe content on page.
The bad news, it only works in Firefox. I've tried it in safari and chrome and it's not working at all. The frame is there but nothing appears in it and nothing happens when I click buttons.
Also, the default frame that I want to start off with appearing in the iframe when the home page loads does not appear but when i click to something else (in firefox, since that's the only browser it works in, as stated before), and then click back to the home page, THEN it appears. Do you think you could help me with these problems? Thanks!
logic_ali — 2011-10-18T20:55:49-04:00 — #12
I need the URL of a live demo.
liligi — 2011-10-18T21:45:13-04:00 — #13
Here you go: http://www.dentalsmilesunlimited.com/htdocs/
The only set of buttons that are working with the iframe right now are the buttons under the "OFFICE" tab. Everything else isn't set up yet, so don't click those.
Don't worry about the iframe being cut off center or the footer not moving with the iframe. Those are all things I will fix later. The most important thing is the iframe and the problems I listed above.
I've got to warn you, I don't know much about jquery. I usually just search around for the effect I want and copy, paste, fill in the spaces, but this is a particular problem that I just can't figure out. I have to embed background music to this thing (I know... tacky), but the only way to make sure the song doesn't restart over and over for every page that is visited is if the main content is in that iframe and the music is stored on the parent page. Thus I really don't have another option... especially since I don't know AJAX either.
Sorry for the long explanation. Just clarifying for you. Take it easy on me. I might ask some newbie questions. Thank you in advance! : )
logic_ali — 2011-10-19T08:47:14-04:00 — #14
For me only Chrome/Safari fails to load content, which I cannot attribute to the resizing code.
On Firefox I.E. and Opera, content loads and resizing operations take place. If you want to prove it, you can enter the following line in the address bar after each different menu selection:
Your page is failing to load "http://www.dentalsmilesunlimited.com/htdocs/js/jquery-1.5.1.js" on account of its absence.
liligi — 2011-10-19T11:31:21-04:00 — #15
Thanks for the quick reply. I took out jquery-1.5.1.js because it was giving me an error WITH it. I figured it was because I made a mistake by loading jquery twice. But the code still works with Opera and FF like you said.
So is it just one of those inexplainable kinks? Since it works in those but not Safari and Chrome?
davidbaldwin — 2012-06-28T21:54:06-04:00 — #16
This is script is great! I use Google Chrome and its works just like it needs to. But, now I opened my test file in Firefox and Safara (Mac I use BTW), and it doesn't work. Do you have any idea why not perhaps? Here's my test-url: http://tinyurl.com/7fkq8oq
logic_ali — 2012-06-29T05:36:31-04:00 — #17
Before trying to diagnose that script, I suggest you fix the indicated script errors.
davidbaldwin — 2012-06-29T10:08:11-04:00 — #18
I'm sorry, but I'm not sure if I understand what you mean: how do I "fix" the errors? Where can I see the errors in the first place? [sorry... but I'm not a js expert :)]
logic_ali — 2012-06-29T11:35:55-04:00 — #19
Error messages are shown in the error console: Ctrl +Shift + J (in Firefox).
The main error seems to stem from this function call: document.fire('dom:loaded');
whose parameter should be an element reference not a string. I suggest you consult whoever wrote that for you.
I ran some tests and it seems that the resizing problem is caused by not having www. in the URL, causing a cross-domain access error.
davidbaldwin — 2012-06-29T11:41:19-04:00 — #20
Well the script I took right at the top of this thread, 2nd post (it's your script :)), so that is why I asked here. I think the www could indeed be an issue, but if I add that to the URL, firefox will simply remove it.*So how could this work, with not having a www in front?
next page →