Joho the BlogA moron sizes an iframe to its contents - Joho the Blog

A moron sizes an iframe to its contents

I know my blogroll is suffering from link rot, so during this holiday interstice, I decided I’d finally get around to fixing it up. But first, to make it super-easy, I decided to put it into an iframe, an html widget that pulls in content from another file. That way I could simply edit a simple file and do so simply, without having to go into the Movable Type template editor. (Yes, I looked at one of the MT plugins, but it requires MT v3.3, and upgrading to v3.2 is a lot like installing 3.3, which I am certain I will screw up.)

So, today I’ve spent several simple hours trying to figure out how to get an iframe to size to its contents. It’s more complex than I can handle. PartMost of the problem is my own vagueness about how the object model works. For example, in the many solutions I found via Google, I’m never quite sure whether the code goes in the container document or the contents document. So, I try both. Every possible freaking variation. Some of the problem is that the object model is so rich with possibilities. Some of the problem is that there are differences among the browsers, so you first have to ask politely (and programmatically) which browser is in use and then provide the appropriate function. And part of it is that it’s too damn hard.

So, I’m giving up for now. And, believe it or not, I’m consoling myself by going back to the chief object of frustration in my life: MythTV.

I just love the holidays, don’t you? [Tags: ]

5 Responses to “A moron sizes an iframe to its contents”

  1. David,

    I assume you’ll hear from lots of people with better solutions, but if you are going to have Javascript anyway, why not just do it with a Javascript file? For example:

    File: embeddedlist.js

    var str = "" +
    "<http://www.firstname.com,First Name>" +
    "<http://www.secondname.com/blog,Second Name blog>" +
    "<http://www.thirdname.com/blogger,Third Name blog>";
    var fullstr = str.replace(/<([^,]*?),([^>]*?)>/g, "<a href='$1'>$2</a><br>");
    document.write(fullstr);
    

    and use it with something like:

    <html>
    <body>
    Here is the test:
    <div style="border:1px solid black;">
    <script type="text/javascript" src="embeddedlist.js"></script>
    </div>
    End of test.
    </body>
    </html>
    

    What this does is take lines of the form:

    <http://url-of-the-blog,Text to have>
    

    and turn it into this where you “call” it in your HTML:

    <a href='http://url-of-the-blog'>Text to have&lt/a><br>
    

    It’s missing the niceities of handling Javascript off, etc., but that’s easy to add. To maintain this, just add new entries as new strings concatenated to the old. Make sure each line (except the last URL) ends with the “+”.

  2. A little off-topic, but “so rich with possibilities” is almost always a component of the problem, a la TV remotes. I know there are times when ‘too many possibilities’ isn’t the problem or a part of it, but those times point to another problem…

    ‘Too many possibilities’ generates plenty of problems, and the lack of possibilities is a problem, so it looks like we’re always a little bit broken again.

    Good luck getting to the point where this particular issue ain’t a problem no more, and Happy New Year.

  3. (OT: Seems as if chineese spammers doesnt’t even need a working internet to spam.)

    David, forget about iframes and all this browser related trouble. Go for server side includes (SSI):

    http://www.spiderpro.com/bu/buphph002.html

    The server will pup together all parts of a page automatically and send a nicely formated HTML page to the browser.

  4. This might help. There’s a typo in the first IF in function autofitIframe()–

    “document.getElemenByID” at the end of the conditional should be “document.getElementById”.

    So, technically, that’s two typos, a missing ‘t’ and ‘ID’ for ‘Id’, but who’s counting. As written that conditional always evaluates FALSE as there is no “getElemenByID”.

  5. Thank you to all. I’m going with Dan’s suggestion for now. It’s working.

    The php includes sound like a good idea, but it seems to require either my changing index.html to index.php, which will break things, or my mucking about with htaccess and other fatal files.

    Wray, thank you for pointing out the typos. D’oh!

    And for those who are puzzled by Mario’s reference to Chinese spammers, that’s because I have since removed some Chinese spam.


Web Joho only

Comments (RSS).  RSS icon