Crossbrowser iframes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christopher Benson-Manica

    #1

    Crossbrowser iframes

    I want to load content into an iframe with script. None of the
    following methods, however, work on all browsers - any suggestions
    would be appreciated.

    // Assume that there is an element whose name and id are both
    // 'theIFrame'.

    var myUrl='http://www.yahoo.com'

    document.getEle mentById( 'theIFrame' ).location=myUr l;

    document.getEle mentById( 'theIFrame' ).src=myUrl;

    window.document .theIFrame.loca tion=myUrl;

    var iframe=document .createElement( 'iframe' );
    iframe.src=myUr l;
    document.body.a ppendChild( iframe );

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
  • kaeli

    #2
    Re: Crossbrowser iframes

    In article <d29mb7$1ql$1@c hessie.cirr.com >, ataru@nospam.cy berspace.org
    enlightened us with...[color=blue]
    > I want to load content into an iframe with script. None of the
    > following methods, however, work on all browsers - any suggestions
    > would be appreciated.
    >[/color]

    Standards support frameElement.sr c, so I'd go with just using that. Both
    Gecko (firefox, moz, NN6+) and MSIE support it.

    MSIE:[color=blue]
    > http://msdn.microsoft.com/workshop/a...ties/src_2.asp[/color]

    Gecko:


    W3C HTML 4.01 specs:
    http://www.w3.org/TR/html4/present/f...ml#edef-IFRAME

    If other browsers can't handle it, oh well. Very few script-type things work
    on every single browser in existence. Actually, if you count the text-only
    browsers, none do! :p
    (do test for an object before using it so it doesn't KILL the non-standard
    browsers)

    You asked for suggestions, so that's just one. I'm sure someone will come
    along with a big long script that works in 15 browsers. *heh*
    AFAIC, I support whatever the W3C has and whatever is needed (if anything) to
    make it work in Firefox and MSIE.

    --
    --
    ~kaeli~
    If that phone was up your a$$, maybe you could drive a
    little better!



    Comment

    • Martin Honnen

      #3
      Re: Crossbrowser iframes



      Christopher Benson-Manica wrote:
      [color=blue]
      > I want to load content into an iframe with script. None of the
      > following methods, however, work on all browsers - any suggestions
      > would be appreciated.
      >
      > // Assume that there is an element whose name and id are both
      > // 'theIFrame'.
      >
      > var myUrl='http://www.yahoo.com'[/color]

      Make sure the name in the <iframe> tag is set then use
      if (window.frames['theIframe']) {
      window.frames['theIframe'].location.href = myUrl;
      }
      That gives you IE 4 and later, Netscape 6 and later, Opera 6 and later
      and hopefully other browsers implementing window.frames.

      --

      Martin Honnen
      http://JavaScript.FAQTs.com/

      Comment

      Working...