How to write a new iframe from inline JS?

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

    How to write a new iframe from inline JS?

    <img src="http://www.6park.com/enter2/av.gif" onload="documen t.write('an
    iframe obj');">

    First of all, it destroy the HTML page.

    Secondly even if it does not destroy it, the iframe object will be within an
    img tag.

    How do I write a new iframe obj outside img tag?


  • Martin Honnen

    #2
    Re: How to write a new iframe from inline JS?



    ok wrote:
    [color=blue]
    > <img src="http://www.6park.com/enter2/av.gif" onload="documen t.write('an
    > iframe obj');">
    >
    > First of all, it destroy the HTML page.
    >
    > Secondly even if it does not destroy it, the iframe object will be within an
    > img tag.
    >
    > How do I write a new iframe obj outside img tag?[/color]

    You can use the DOM to create an iframe dynamically with IE5+, Netscape
    6+, Opera 7 and other DOM compliant browsers:

    function createIframe (iframeName, iframeSrc) {
    var iframe;
    if (document.creat eElement && (iframe =
    document.create Element('iframe '))) {
    iframe.name = iframeName;
    iframe.src = iframeSrc;
    document.body.a ppendChild(ifra me);
    }
    }

    <img onload="createI frame('iframeNa me', 'whatever.html' );"
    src="whatever.g if" alt="what ever">

    --

    Martin Honnen

    Comment

    • ok

      #3
      Re: How to write a new iframe from inline JS?

      > <img src="http://www.6park.com/enter2/av.gif" onload="documen t.write('an[color=blue]
      > iframe obj');">
      >
      > First of all, it destroy the HTML page.
      >
      > Secondly even if it does not destroy it, the iframe object will be within[/color]
      an[color=blue]
      > img tag.
      >
      > How do I write a new iframe obj outside img tag?
      >
      >[/color]

      By the way, a plain IFRAME tag is not allowed anywhere in the html


      Comment

      • Robert

        #4
        Re: How to write a new iframe from inline JS?

        "ok" <a@b.c> wrote in message news:<415295c1@ news01.argolink .net>...[color=blue]
        > <img src="http://www.6park.com/enter2/av.gif" onload="documen t.write('an
        > iframe obj');">[/color]

        This is a strange directive. What you are saying is that when the
        image gets loaded from the server, you want run the function
        document.write. Assuming for a moment that document.write might do
        something valid, it would insert into the document the phrase 'an
        iframe obj'. Document.write takes as input normal html.
        You would expect something like:
        document.write( "<iframe src='myiframe.h tml'><\/iframe>");
        However, this wouldn't work in your situation.

        It would appear that you are trying to set a message in the page when
        the loading of the image is complete.
        [color=blue]
        >
        > First of all, it destroy the HTML page.[/color]

        How true. Document.write is designed to be used as the html is being
        constructed. Once a web browser see the </html> tag, you can no
        longer use the document.write function.
        [color=blue]
        >
        > How do I write a new iframe obj outside img tag?[/color]

        I assumed you were using the image as a button and wrote the follow
        code. When I wrote the code, I didn't realize that you where using
        the onload event handler. I assumed onclick. To change to the onload
        do something like:
        <img src="http://www.6park.com/enter2/av.gif"
        onload="insertI frame();">

        Notice that I have a div where the iframe will be inserted.

        I tested this with macos 10.2.6 with IE 5.2 and netscape 7.3.

        Robert


        insert.html
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
        <html>
        <head>
        <title>insert an iframe</title>

        <script type="text/javascript">
        function insertIframe ()
        {
        var node;
        if (document.getEl ementById)
        {
        node = document.getEle mentById("ifram ediv");
        if (node)
        {
        var myElement = document.create Element("DIV");
        node.appendChil d(myElement);

        myElement.inner HTML =
        "<iframe src='myiframe.h tml' " +
        "width='400 ' height='160'></iframe> " ;
        }
        else
        {
        alert("The function insertIframe could not find " +
        "the tag iframediv.");
        return;
        }
        }
        else
        {
        alert(" document.getEle mentByID failed. " );
        return;
        }

        }
        </script>
        </head>
        <body>
        <p>Insert an iframe.
        <br>
        Don't forget to see what happens when you
        press the button more than once.</p>
        <form>
        <input type="button"
        name="activate"
        value="insert the iframe"
        onclick="insert Iframe();">
        <br>
        </form>
        <div id='iframediv'>
        </div>
        </body>
        </html>

        myiframe.html
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
        <html>
        <head>
        <title>this is myiframe</title>
        </head>
        <body>
        <p>This iframe was inserted by innerHTML.
        <br>
        This is amazing!</p>
        </body>
        </html>

        Comment

        • Randy Webb

          #5
          Re: How to write a new iframe from inline JS?

          Robert wrote:[color=blue]
          > "ok" <a@b.c> wrote in message news:<415295c1@ news01.argolink .net>...[/color]

          <--snip-->
          [color=blue][color=green]
          >>First of all, it destroy the HTML page.[/color]
          >
          >
          > How true. Document.write is designed to be used as the html is being
          > constructed. Once a web browser see the </html> tag, you can no
          > longer use the document.write function.[/color]

          Yes you can.

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
          "http://www.w3.org/TR/REC-html40/strict.dtd">
          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
          <title>Blank Test Page</title>
          <style type="text/css">
          </style>
          <script type="text/javascript">
          </script>
          </head>
          <body>
          Body Text
          </body>
          </html>
          <script type="text/javascript">
          document.write( 'New Body Text')
          </script>


          --
          Randy
          comp.lang.javas cript FAQ - http://jibbering.com/faq

          Comment

          • Robert

            #6
            Re: How to write a new iframe from inline JS?

            Randy Webb <HikksNotAtHome @aol.com> wrote in message news:<XtmdnfZQb rZI0cncRVn-hA@comcast.com> ...[color=blue]
            > Robert wrote:[color=green]
            > > "ok" <a@b.c> wrote in message news:<415295c1@ news01.argolink .net>...[/color]
            >
            > <--snip-->
            >[color=green][color=darkred]
            > >>First of all, it destroy the HTML page.[/color]
            > >
            > >
            > > How true. Document.write is designed to be used as the html is being
            > > constructed. Once a web browser see the </html> tag, you can no
            > > longer use the document.write function.[/color]
            >
            > Yes you can.
            >[/color]

            So I see. Any utility in it? Why would I want to do this? Is it
            really valid since there should be no tags nor data after the </html>
            that I am aware?

            This should suffice:
            Once a web browser see the </html> tag, you should no
            longer use the document.write function.


            You can always use the document.write as the OP did, but it will not
            likely yeild the results expected ;-).

            Robert

            Comment

            • Randy Webb

              #7
              Re: How to write a new iframe from inline JS?

              Robert wrote:[color=blue]
              > Randy Webb <HikksNotAtHome @aol.com> wrote in message news:<XtmdnfZQb rZI0cncRVn-hA@comcast.com> ...
              >[color=green]
              >>Robert wrote:
              >>[color=darkred]
              >>>"ok" <a@b.c> wrote in message news:<415295c1@ news01.argolink .net>...[/color]
              >>
              >><--snip-->
              >>[color=darkred]
              >>>>First of all, it destroy the HTML page.
              >>>
              >>>
              >>>How true. Document.write is designed to be used as the html is being
              >>>constructe d. Once a web browser see the </html> tag, you can no
              >>>longer use the document.write function.[/color]
              >>
              >>Yes you can.
              >>[/color]
              >
              >
              > So I see. Any utility in it? Why would I want to do this? Is it
              > really valid since there should be no tags nor data after the </html>
              > that I am aware?[/color]

              No real utility in it, just a reality (most of the time), with ad
              inserting servers that either prepend the ad code, or append it to the
              document. In that event, you can end up with some really wierd things
              before the DTD and after the initial </html> and no its nowhere close to
              valid code.
              [color=blue]
              > This should suffice:
              > Once a web browser see the </html> tag, you should no
              > longer use the document.write function.[/color]

              Yes, that suffices.
              [color=blue]
              > You can always use the document.write as the OP did, but it will not
              > likely yeild the results expected ;-).[/color]

              How true :) Depending on who is predicting the expected results :)

              --
              Randy
              comp.lang.javas cript FAQ - http://jibbering.com/faq

              Comment

              Working...