News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Dynamicly resize iframe in Wordpress

Started by E221b, August 29, 2013, 06:51:29 PM

Previous topic - Next topic

E221b

Hi,

I'm embedding my SMF into my Wordpress blog (which is at hxxp:ffredemption.com/forums/ [nonactive]) by using an iFrame in the appropriate page template. It works okay, except I can't get it to dynamically resize based on the content. So the forum mainpage fills the iframe and it's great, but when I click through to a subforum or topic, the iframe is either too long or too short (hasn't happened yet, since no posts yet).

I'm using a dynamic resize bit of javascript but it doesn't seem to do anything.

<script type='text/javascript'>

function setIframeHeight( iframeId ) /** IMPORTANT: All framed documents *must* have a DOCTYPE applied **/
{
var ifDoc, ifRef = document.getElementById( iframeId );

try
{   
  ifDoc = ifRef.contentWindow.document.documentElement; 
}
catch( e )
{
  try
  {
   ifDoc = ifRef.contentDocument.documentElement; 
  }
  catch(ee)
  {   
  } 
}

if( ifDoc )
{
  ifRef.height = 1; 
  ifRef.height = ifDoc.scrollHeight;
}
}

</script>

<?php get_header(); ?>
<iframe style="overflow:hidden;width:1000px;height:100%;" frameborder="0" name="content" allowtransparency="true" src="/forum" scrolling="no" onLoad="setIframeHeight( this.id )"></iframe>


Any help or advice to make the iframe correctly resize based upon the forum content?

-B

E221b

I've also tried this to similar/no effect:

<script type="text/javascript">
         function calcHeight()
         {
         //find the height of the internal page
         var the_height=
         document.getElementById('the_iframe').contentWindow.
         document.body.scrollHeight;

         //change the height of the iframe
         document.getElementById('the_iframe').height=
         the_height;
         }
</script>

Advertisement: