Sending html data to the IFrame contents

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Chen

    #1

    Sending html data to the IFrame contents

    I need to use iframe to create a floating frame. But the contents in the
    iframe is not a external html file. Rather, it will be dynamically created
    by jsp. How can I set the src attribute to a URL of a dynamically created
    html contents rather than a static html file. Thanks.



  • Douglas Crockford

    #2
    Re: Sending html data to the IFrame contents

    > I need to use iframe to create a floating frame. But the contents in the[color=blue]
    > iframe is not a external html file. Rather, it will be dynamically created
    > by jsp. How can I set the src attribute to a URL of a dynamically created
    > html contents rather than a static html file. Thanks.[/color]

    Your notion of dynamic and static in this case is strictly on the server's side.
    All the browser knows is that it gets a wad of html via http. All such wads are
    provided in response to the browser sending a url in an http request. The shape
    of that url depends on the application running in the appserver.

    Comment

    • DU

      #3
      Re: Sending html data to the IFrame contents

      John Chen wrote:
      [color=blue]
      > I need to use iframe to create a floating frame.[/color]

      I do not understand what you mean with "floating" frame.
      An url of your current webpage would have been useful here.

      But the contents in the[color=blue]
      > iframe is not a external html file. Rather, it will be dynamically created
      > by jsp. How can I set the src attribute to a URL of a dynamically created
      > html contents rather than a static html file.[/color]

      Not sure I understand correctly your question.
      You can use DOM 2 methods to create a chunk of html code (or even
      document fragment) and then insert it (almost anywhere, at any place)
      into the iframed document. Or append it. Or replace current html content
      of the iframe. Whatever you do, the src attribute value of the iframe
      should not change.

      E.g.: appending a div in a iframe from its own parent file

      <script type="text/javascript">
      function appendDivInIfra medDocument()
      {
      var DOMdiv = frames["IframeName "].document.creat eElement("div") ;
      DOMdiv.style.co lor = "green";
      var DOMspan = frames["IframeName "].document.creat eElement("span" );
      DOMspan.style.c olor = "red";
      var DOMspantext = frames["IframeName "].document.creat eTextNode("This is
      the text node value of the span and it is red");
      DOMspan.appendC hild(DOMspantex t);
      DOMdiv.appendCh ild(DOMspan);
      var DOMdivtext = frames["IframeName "].document.creat eTextNode(" while
      this green text is part of the div text node. The green and red text
      were dynamically inserted in the iframed document.");
      DOMdiv.appendCh ild(DOMdivtext) ;
      frames["IframeName "].document.body. insertBefore(DO Mdiv,
      frames["IframeName "].document.body. childNodes[1]);
      document.getEle mentById("Butto nCreateAndInser t").disabled = true;
      }
      </script>
      </head>

      <body>

      <iframe src="OriginalDo cumentIframe.ht ml" name="IframeNam e" width="500"
      height="200" style="border:3 px solid blue;">[Your user agent does not
      support iframes or is currently configured not to display iframes. If
      you're using Opera 6+, you can enable iframe with
      File/Preferences...A lt+P/Page style/Enable inline frames.]</iframe>

      <p><button type="button" id="ButtonCreat eAndInsert"
      onclick="append DivInIframedDoc ument();">Creat e and insert a div into the
      Iframe document</button></p>

      (...)

      Works in MSIE 6 for Windows, Opera 7, Mozilla-based browsers, NS 7.1,
      etc.. and in other DOM 2 compliant browsers as long as the markup code
      syntax is valid.

      DU
      --
      Javascript and Browser bugs:

      - Resources, help and tips for Netscape 7.x users and Composer
      - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


      Comment

      • Chris Riesbeck

        #4
        Re: Sending html data to the IFrame contents

        In article <t9q9b.468155$u u5.81229@sccrns c04>,
        "John Chen" <johnhchen@comc ast.net> wrote:
        [color=blue]
        > I need to use iframe to create a floating frame. But the contents in the
        > iframe is not a external html file. Rather, it will be dynamically created
        > by jsp. How can I set the src attribute to a URL of a dynamically created
        > html contents rather than a static html file. Thanks.[/color]

        There's no difference. Just write the URL for the JSP as
        you would an HTML file. The browser just sends the URL
        to the server and displays in the frame whatever
        the server returns.

        Comment

        Working...