Auto height iframe

Discussion in 'Programming' started by swmasson, Aug 10, 2008.

to remove all ads.
  1. swmasson

    swmasson New Member

    Messages:
    17
    Hi there,

    I'm trying to automatically resize the height of an iframe depending on the content of the webpage it displays...

    basically i want word press to display within my current web template....

    does anyone know of a code that works? i've tried at least 10 different codes and non actyually work...

    Thanks for your help

    Regards

    SWM
     
  2. jnjc

    jnjc New Member

    Messages:
    493
    As far as I know you'll need to use some javascript to size the iframe. Do a search on it and you should see some examples.

    HTH,
    JC
     
  3. swmasson

    swmasson New Member

    Messages:
    17
    Thanks againa, however, i've searched all day and tried well over 10 examples... none seemed to work... i'm not sure its even possible...
     
  4. athomas

    athomas New Member

    Messages:
    145
    It isn't possible. Use php includes.
     
  5. joe

    joe New Member

    Messages:
    82
    have you tried leaving the off the height tab
     
  6. Dronesypa

    Dronesypa New Member

    Messages:
    5
    Its possible, however if you write a single line of text, that's how big your iframe is going to be. I am working on the same issue as you are. I have seen some people use a DIV and measure the length of it and set that to the iframe length.
     
  7. AE7

    AE7 New Member

    Messages:
    53
    I think it's possible... As said above, Javascript....
     
  8. Richardvd

    Richardvd New Member

    Messages:
    32
    It is possible with a JavaScript, but it don't works with all browsers. I had the same question a few months ago, the right solution for me was to use a div with scrollbar. An another chance was the positive influence for Google.
     
  9. walkingbird

    walkingbird New Member

    Messages:
    101
    Do not use frames they are old technology. It will drastically effect the usability of your web site for users and search engines.
     
  10. dumb_prog

    dumb_prog New Member

    Messages:
    4
    easy!

    place a inner div inside iframe area

    Get the height of the div, use this javascript.

    function getHeight(){

    var d=document;
    var box=new Array("div id","div id 2");
    for(x=0;x<box.length;x++){
    h=d.getElementById(box[x]).offsetHeight;
    for(y=0;y<box.length;y++){
    test_h=d.getElementById(box[y]).offsetHeight;
    if(h<test_h)h=test_h;
    }

    Once you get the height of the div, size your iframe height based on getheight().
     
  11. athomas

    athomas New Member

    Messages:
    145
    That's not a good idea in and of itself though. Iframes aren't made to resize.

    Use a php include like this:

    <?php

    if (isset($_GET['page'])) {
    switch ($_GET['page']) {

    case "something":
    include ('something.php');
    break;

    default :
    include 'home.php';
    break;
    }
    } else {

    include 'somefile.php';
    }
    ?>


    Just put that where you want to have the content come out, and have links look like this:

    www.yoursite.com/index.php?page=something

    Obiviously you can change something to whatever you want... Ask if it doesn't make sense.
     
  12. jnjc

    jnjc New Member

    Messages:
    493
    I might be missing something but to me this looks like it will only work for content located locally on the server. It won't work where the frame src is a url.

    Likewise for the solution 'dumb_prog" sent in, to me (and again I might be missing something) looks like it would only work if the contents of the iframe are placed inside the div. I have a feeling that the poster whats to use an iframe along the lines of :

    Code:
    <iframe src="http://alinktosomething.com"></iframe> 
    and have the iframe resize automatically.

    I have done a little bit of testing and I can't get anything to work either. In my opinion and based on the fact that I'm assuming you are trying to use an iframe as I have outlined above, I think it's time for plan b....

    I've never used wordpress but I'm sure you'll be able to use an API to integrate it into your website..
     
    Last edited: Sep 11, 2008
  13. athomas

    athomas New Member

    Messages:
    145
    Iframes aren't web 2.0 at all. It's old and frankly nobody really uses them that much anymore. Most sites arent even saved in *.html anymore.
     
  14. dumb_prog

    dumb_prog New Member

    Messages:
    4
    I'm pretty sure it will work for frame src = url, since I have been using it on ajax (dynamically loads the content inside the div) as well.
     
  15. jnjc

    jnjc New Member

    Messages:
    493
    I could see how it would work with ajax because with an ajax call you will be putting the returned code into the div, the div will re-size itself and then your code will resize the iframe. With the <iframe src="url" ... no content goes into the div, hence the div will not re-size and your script won't work.

    All this said I haven't had a chance to test it out so I'm not 100% sure....
     

Share This Page