SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: iframe question

  1. #1
    SitePoint Zealot
    Join Date
    Aug 2009
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    iframe question

    Hello

    I want to put an iframe into my web page.
    Is there a way I can only have it display a portion of the
    iframe src url?

    For example, I don't want the left and right side navigation panes,
    only the middle portion.

    Code:
    <iframe src="http://mysite.com" frameborder="0" width="800" height="1000" scrolling="auto"></iframe>

    Thanks.

  2. #2
    Mouse catcher silver trophy Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,888
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Is the iframe source on your site or someone else's?

    If it's on your site, can you not recode it somehow so that the section is there as a stand-alone page as well as a full page with navigation?

    Of course, there's still the question of why you're using iframes, which are not generally a good answer to any question...

  3. #3
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,355
    Mentioned
    179 Post(s)
    Tagged
    6 Thread(s)
    You could put the iframe in a div that is smaller than the iframe and use overflow:hidden on the div to hide the excess. Then just drag the iframe to the side to reveal only the middle section.

    e.g.
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    #iframe {
        border:10px solid red;
        overflow:hidden;
        background:red;
        width:760px;
        margin:auto;
        height:500px;
    }
    #iframe iframe {
        width:1000px;
        height:100%;
        margin-left:-260px;
    }
    </style>
    </head>
    <body>
    <div id="iframe">
        <iframe src="http://www.pmob.co.uk/"></iframe>
    </div>
    </body>
    </html>
    Of course iframes should be avoided if at all possible. (And if you are viewing a site not belonging to you in the iframe then you probably need their permission).

  4. #4
    SitePoint Zealot PatrickSamphire's Avatar
    Join Date
    Jul 2006
    Location
    UK
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the source is on one of your sites, there are many better ways of doing this. If not, you probably shouldn't be doing it at all.

  5. #5
    SitePoint Enthusiast scout1idf's Avatar
    Join Date
    Nov 2009
    Location
    Ohio
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    These responses......

    Quote Originally Posted by Stevie D View Post
    .......Of course, there's still the question of why you're using iframes, which are not generally a good answer to any question...
    Quote Originally Posted by Paul O'B View Post
    ........Of course iframes should be avoided if at all possible. (And if you are viewing a site not belonging to you in the iframe then you probably need their permission).
    Quote Originally Posted by PatrickSamphire View Post
    ........there are many better ways of doing this........
    .....bring up a question a question that has bugged me for a while.

    What's wrong with <frames> and <iframes> ?

    When I first started learning a few years ago, all I read was don't use <frames> use <iframes> instead.

    Now I'm reading here, don't use <iframes> either.

    Why not?


    I play an on-line fantasy RPG that started out using <frames> and now I see that the he has switched to <iframes>. Both work/worked great, so that makes me really wonder "what's wrong with them?"

    I'm asking because I've seen their use put down without explanation. Just avoid them.

    Thanks.

  6. #6
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by scout1idf View Post
    so that makes me really wonder "what's wrong with them?"
    Frames (be it frameset OR iframe) are an accessibility failure. Many screen readers will fail to read their content, they usually break keyboard navigation, it prevents people from directly linking to content, the contents of the frame are treated separately from the actual page link by search engines, it requires more handshakes to the server which can usually mean slower loading pages despite any reduction in bandwidth -- and it can often use MORE bandwidth since the content of each separate section is accompanied by an extra HEAD.

    The same can be said for DHTML and AJAX when it comes to delivering content -- A dearly departed friend of mine called AJAX when used for things like tabs "The new framesets" -- and that was NOT meant as a compliment.

    The reasons to use them are often outweighed by the reasons not to. If you practice semantic markup, separation of presentation from content, and build/include your markup's static bits server-side (php, asp, shtml for example), everything else on the page should be cached and that extra two or three k on the page load really shouldn't have an impact with everything else cached.

    Of course, if you aren't practicing modern coding techniques and have 20k to 50k of static markup for a template without the actual content in it, you won't understand a word of the above...

    Which is what makes it funny when things like frames, iframes, DHTML and AJAX are touted as bandwidth savers by people using 100k of HTML to deliver 5k of content -- basically the same people who vomit up pages any-old-way then practice white-space stripping to obfuscate their ineptitude.

    NOT to say I'm singling you out for that - "your first page" is fairly lean and a decent attempt -- it does have SOME issues, but as a first page you're already light-years ahead of many people who've been at it for years. I mean you issues are minor -- multiple H1's, H3's around non-heading elements, DIV id="header" around what SHOULD BE your H1, H3's without the preceding H2, nonsensical heading tag orders, some unnecessary classes and DIV, non-breaking spaces used to handle formatting, as well as a handful of design issues like alpha transparency on the backgrounds making it painful to scroll in Firefox on anything less than a quad core machine...

    As a "first out" that's still not bad.

  7. #7
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,355
    Mentioned
    179 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by scout1idf View Post
    These responses......

    .bring up a question a question that has bugged me for a while.

    What's wrong with <frames> and <iframes> ?

    .
    Usually the main reason for not using them is that there are much better and more accessible solutions. More info here and here. Iframes can also pose security problems so a number of users will have them switched off anyway to avoid the results of iframe injection attacks which can happen to sites that you may trust.

  8. #8
    SitePoint Enthusiast scout1idf's Avatar
    Join Date
    Nov 2009
    Location
    Ohio
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the info both of you.

    After reading the part about the screen readers, it makes me wonder what our Game Master does to his pages. We have many blind players that don't have any problem. In fact, on the games home page, he has a link for suggestions on how to improve the game for the blind.

    Again, thanks for the info.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •