User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 374,611 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,455 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 66374 | Replies: 6
Reply
Join Date: Feb 2004
Posts: 11
Reputation: fred999 is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
fred999 fred999 is offline Offline
Newbie Poster

Dynamic iframe height

  #1  
Nov 29th, 2004
Hi all, how would you adjust the height of an iframe based on its src content?

I want to integrate a forum (phpbb) inside my custom made website. The problem is that there is no way to dynamically adjust the iframe height... im pulling out my hair here...

I thought javascript would be the best way to do that, the problem is that i know nothing about JS... Here is my idea,

-2 scripts, 1 in the parent page (the one with the iframe tag) and the second one in the main forum page

-The script inside the parent page, would dynamically set the "height" parameter inside the iframe tag based on a value passed by the second script.

-The second script, inside the forum page, would read the entire content of the (document.body.scrollHeight) current page and sends its result to the first script

I have found a script that was supposed to do that, but for some reasons it doesnt work very well. Here is the link where i explain de problem with it: http://www.dynamicdrive.com/forums/s...ted=1#post2891

Now, what do the experts think? do you think its gonna work? Is this a bad idea? Please i need help bad.

Thanks in advance,

fred
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2005
Location: Atlanta
Posts: 7
Reputation: ipodgirl is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ipodgirl's Avatar
ipodgirl ipodgirl is offline Offline
Newbie Poster

Re: Dynamic iframe height

  #2  
Mar 2nd, 2005
If you are trying to do that for pages within the same domain, this script should do the trick:

http://www.dynamicdrive.com/dynamici...iframessi2.htm
Reply With Quote  
Join Date: Jun 2006
Posts: 1
Reputation: joshkotecha is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
joshkotecha joshkotecha is offline Offline
Newbie Poster

Re: Dynamic iframe height

  #3  
Jun 28th, 2006
Did you find a solution? I'm trying to do something very similar and have some problems with the dyniframe.js you reference.


Originally Posted by fred999
Hi all, how would you adjust the height of an iframe based on its src content?

I want to integrate a forum (phpbb) inside my custom made website. The problem is that there is no way to dynamically adjust the iframe height... im pulling out my hair here...

I thought javascript would be the best way to do that, the problem is that i know nothing about JS... Here is my idea,

-2 scripts, 1 in the parent page (the one with the iframe tag) and the second one in the main forum page

-The script inside the parent page, would dynamically set the "height" parameter inside the iframe tag based on a value passed by the second script.

-The second script, inside the forum page, would read the entire content of the (document.body.scrollHeight) current page and sends its result to the first script

I have found a script that was supposed to do that, but for some reasons it doesnt work very well. Here is the link where i explain de problem with it: http://www.dynamicdrive.com/forums/s...ted=1#post2891

Now, what do the experts think? do you think its gonna work? Is this a bad idea? Please i need help bad.

Thanks in advance,

fred
Reply With Quote  
Join Date: Oct 2006
Location: Indonesia
Posts: 1
Reputation: hilmanDev is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
hilmanDev hilmanDev is offline Offline
Newbie Poster

Re: Dynamic iframe height

  #4  
Oct 2nd, 2006
Originally Posted by joshkotecha View Post
Did you find a solution? I'm trying to do something very similar and have some problems with the dyniframe.js you reference.


I have found the solution for your problem based on dyniframe.js
I hope this solution is meaningful for you :cheesy:

The solution is you have to put last statement into new own function. and every page that you want to load into the frame call parent function that you created before. For example :

in Main Page (before) :

[html]<Script>
...
...
if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller
</Script>[/html]

Change into :
[html]<Script>
...
...
function onLoadPage() {
if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller
}
</script>[/html]

On every frame page put script on body tag like this :
[html]<body onLoad="parent.onLoadPage();">
...
...
</body>[/html]
Last edited by tgreer : Oct 2nd, 2006 at 9:26 am. Reason: User ignored directions for code tags.
Reply With Quote  
Join Date: Nov 2006
Posts: 1
Reputation: vbnullchar is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
vbnullchar vbnullchar is offline Offline
Newbie Poster

Re: Dynamic iframe height

  #5  
Nov 27th, 2006
What if my source is from other domain? this is my problem right now?

Originally Posted by hilmanDev View Post
I have found the solution for your problem based on dyniframe.js
I hope this solution is meaningful for you :cheesy:

The solution is you have to put last statement into new own function. and every page that you want to load into the frame call parent function that you created before. For example :

in Main Page (before) :

[html]<Script>
...
...
if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller
</Script>[/html]
Change into :
[html]<Script>
...
...
function onLoadPage() {
if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller
}
</script>[/html]
On every frame page put script on body tag like this :
[html]<body onLoad="parent.onLoadPage();">
...
...
</body>[/html]
Reply With Quote  
Join Date: Feb 2008
Posts: 1
Reputation: dreambouy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
dreambouy dreambouy is offline Offline
Newbie Poster

Solution Re: Dynamic iframe height

  #6  
Feb 9th, 2008
Folks, To fix the iframe height issue, I added the following code at the end of my page.(page within the iframe)

  1. <script type="text/javascript">
  2. parent.window.document.getElementById("<FRAME_NAME>").height = document.body.offsetHeight ;
  3. </script>

It worked perfectly. At some places, the height was not coming properly, so I added 25 or 50 to reach my requirement. Try using this in the above code..
document.body.offsetHeight + 25

Try it out and let me know if you find any issues.
Last edited by peter_budo : Mar 22nd, 2008 at 3:12 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Mar 2008
Posts: 2
Reputation: Griffin54 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Griffin54 Griffin54 is offline Offline
Newbie Poster

Re: Dynamic iframe height

  #7  
Mar 21st, 2008
Hello all;

I have been having problems with an iframe application too. However, my problem only seems to appear when I test my site on the FireFox browser. My iframe appears properly in IE and Opera. Below is the syntax I used.

In the "body" of my webpage I wrote the following:

  1. <div id="frame">
  2. <iframe id="secondFrame" name="secondFrame" width="50%" height="500em" frameborder="1" scrolling="auto" src="iframeimagesrc.htm">
  3. </iframe>
  4. </div>

In my "CSS" file I wrote the following:

  1. div#frame { text-align: center;
  2. padding: 10px; }

Any ideas why my iframe works in IE and Opera but not in FireFox??

Thanks, Griffin54
Last edited by peter_budo : Mar 22nd, 2008 at 3:13 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 8:28 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC