Getting IFRAME text

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

    Getting IFRAME text

    <iframe name="iframe" width="100%" height="25%" src="test1.txt" >
    </iframe>

    <a href="test1.txt " target="input"> one</a>
    <a href="test2.txt " target="input"> two</a>

    <form name="form1">
    <textarea name="textarea" cols=80 rows=18>
    This is a test
    </textarea><br>
    <button name="Copy" value="Copy" OnClick="DoCopy ()">Copy</button>
    </form>

    <script>

    function DoCopy()
    {
    form1.textarea. value=iframe.in nerText;
    }
    </script>


  • Aaron Gray

    #2
    Re: Getting IFRAME text

    Whoops, forgot the question !

    I want to copy the text from a text document opened in an iframe into a
    textarea at th press of a button.
    [color=blue]
    > <iframe name="iframe" width="100%" height="25%" src="test1.txt" >
    > </iframe>
    >
    > <a href="test1.txt " target="input"> one</a>
    > <a href="test2.txt " target="input"> two</a>
    >
    > <form name="form1">
    > <textarea name="textarea" cols=80 rows=18>
    > This is a test
    > </textarea><br>
    > <button name="Copy" value="Copy" OnClick="DoCopy ()">Copy</button>
    > </form>
    >
    > <script>
    >
    > function DoCopy()
    > {
    > form1.textarea. value=iframe.in nerText;
    > }
    > </script>[/color]

    I tried 'iframe.body.in nerText' but that did not work.

    Aaron


    Comment

    • VK

      #3
      Re: Getting IFRAME text


      Aaron Gray wrote:[color=blue]
      > Whoops, forgot the question !
      >
      > I want to copy the text from a text document opened in an iframe into a
      > textarea at th press of a button.
      >[color=green]
      > > <iframe name="iframe" width="100%" height="25%" src="test1.txt" >
      > > </iframe>
      > >
      > > <a href="test1.txt " target="input"> one</a>
      > > <a href="test2.txt " target="input"> two</a>
      > >
      > > <form name="form1">
      > > <textarea name="textarea" cols=80 rows=18>
      > > This is a test
      > > </textarea><br>
      > > <button name="Copy" value="Copy" OnClick="DoCopy ()">Copy</button>
      > > </form>
      > >
      > > <script>
      > >
      > > function DoCopy()
      > > {
      > > form1.textarea. value=iframe.in nerText;
      > > }
      > > </script>[/color]
      >
      > I tried 'iframe.body.in nerText' but that did not work.
      >
      > Aaron[/color]


      <iframe name="iframe01" width="100%" height="25%" src="test1.txt" >
      </iframe>

      <form name="form1">
      <textarea name="txt01" cols=80 rows=18>
      This is a test
      </textarea><br>
      <button name="Copy" value="Copy" OnClick="DoCopy ()">Copy</button>
      </form>


      <script>


      function DoCopy()
      {
      document.forms['form1'].elements['txt01'].value =
      document.frames['iframe01'].document.body. innerHTML;
      }
      </script>



      1) Never ever give the names/id using generic html element names
      ("iframe", "textarea" etc.)

      2) <http://www.javascriptt oolbox.com/bestpractices/> see about
      addressing frames/form elements - helps a lot.

      ;-)

      Comment

      • Aaron Gray

        #4
        Re: Getting IFRAME text

        > 1) Never ever give the names/id using generic html element names[color=blue]
        > ("iframe", "textarea" etc.)[/color]

        Okay :)
        [color=blue]
        > 2) <http://www.javascriptt oolbox.com/bestpractices/> see about
        > addressing frames/form elements - helps a lot.[/color]

        This does not deal with getting the text from a text document in an iframe
        which is what I was after.

        Aaron


        Comment

        • Martin Honnen

          #5
          Re: Getting IFRAME text



          Aaron Gray wrote:
          [color=blue]
          > <iframe name="iframe" width="100%" height="25%" src="test1.txt" >
          > </iframe>[/color]

          Is that really a text/plain document in the iframe? Or a text/html
          document? Obviously the DOM is defined for (structured) HTML and XML
          documents but not for (unstructured) text documents.
          Though some browser (IE, Mozilla too perhaps) might expose a document
          with a body for text, see below.
          [color=blue]
          > <form name="form1">
          > <textarea name="textarea" cols=80 rows=18>
          > This is a test
          > </textarea><br>
          > <button name="Copy" value="Copy" OnClick="DoCopy ()">Copy</button>[/color]

          <input type="button" value="Copy"
          onclick="DoCopy (this.form.elem ents.textarea, 'iframe')">

          [color=blue]
          > function DoCopy()[/color]

          function DoCopy (textControl, iframeName) {
          if (window.frames && window.frames[iframeName] &&
          window.frames[iframeName].document &&
          window.frames[iframeName].document.body &&
          window.frames[iframeName].document.body. innerHTML)
          {
          textControl.val ue =
          window.frames[iframeName].document.body. innerHTML;
          }
          }

          --

          Martin Honnen

          Comment

          • Aaron Gray

            #6
            Re: Getting IFRAME text

            > <input type="button" value="Copy"[color=blue]
            > onclick="DoCopy (this.form.elem ents.textarea, 'iframe')">
            >
            > function DoCopy (textControl, iframeName) {
            > if (window.frames && window.frames[iframeName] &&
            > window.frames[iframeName].document &&
            > window.frames[iframeName].document.body &&
            > window.frames[iframeName].document.body. innerHTML)
            > {
            > textControl.val ue =
            > window.frames[iframeName].document.body. innerHTML;
            > }
            > }
            >[/color]

            Great, the text appears as a <pre> block, but using InnerText rather than
            innerHTML sorts that out and just copies the raw text :)

            Thanks alot,

            Aaron


            Comment

            • Randy Webb

              #7
              Re: Getting IFRAME text

              Aaron Gray said the following on 11/10/2005 3:57 PM:
              [color=blue][color=green]
              >> <input type="button" value="Copy"
              >> onclick="DoCopy (this.form.elem ents.textarea, 'iframe')">
              >>
              >> function DoCopy (textControl, iframeName) {
              >> if (window.frames && window.frames[iframeName] &&
              >> window.frames[iframeName].document &&
              >> window.frames[iframeName].document.body &&
              >> window.frames[iframeName].document.body. innerHTML)
              >> {
              >> textControl.val ue =
              >> window.frames[iframeName].document.body. innerHTML;
              >> }
              >> }
              >>[/color]
              >
              >
              > Great, the text appears as a <pre> block, but using InnerText rather than
              > innerHTML sorts that out and just copies the raw text :)[/color]

              And only works in IE since innerText is IE proprietary code.

              --
              Randy
              comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
              Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

              Comment

              • Aaron Gray

                #8
                Re: Getting IFRAME text

                >> Great, the text appears as a <pre> block, but using InnerText rather than[color=blue][color=green]
                >> innerHTML sorts that out and just copies the raw text :)[/color]
                >
                > And only works in IE since innerText is IE proprietary code.[/color]

                Okay, I will have to do a workaround at some point :(

                Aaron


                Comment

                • Thomas 'PointedEars' Lahn

                  #9
                  Re: Getting IFRAME text

                  Aaron Gray wrote:
                  [color=blue][color=green]
                  >> 1) Never ever give the names/id using generic html element names
                  >> ("iframe", "textarea" etc.)[/color]
                  >
                  > Okay :)[/color]

                  Don't listen to what V'often wrong'K is telling you. There is nothing
                  wrong in using such names, there is no known side effect in any language
                  or UA. What is true is that it is a Good Thing to choose names with
                  meaning; for example, the `textarea' element could be named according
                  to its expected content.
                  [color=blue][color=green]
                  >> 2) <http://www.javascriptt oolbox.com/bestpractices/> see about
                  >> addressing frames/form elements - helps a lot.[/color]
                  >
                  > This does not deal with getting the text from a text document
                  > in an iframe which is what I was after.[/color]

                  Try referenceToIfra me.document.bod y.firstChild.fi rstChild.nodeVa lue in
                  Mozilla/5.0. WFM in Firefox 1.0.7/Linux as an iframe with a plaintext
                  resource is made available through an embedded HTML document with a
                  `pre' element containing the resource's content.


                  PointedEars

                  Comment

                  • Thomas 'PointedEars' Lahn

                    #10
                    Re: Getting IFRAME text

                    Aaron Gray wrote:
                    [color=blue]
                    > Great, the text appears as a <pre> block, but using InnerText rather than
                    > innerHTML sorts that out and just copies the raw text :)[/color]

                    Note that innerText (JS is case-sensitive) is an IE-proprietary property.


                    PointedEars

                    Comment

                    • Aaron Gray

                      #11
                      Re: Getting IFRAME text

                      > Don't listen to what V'often wrong'K is telling you. There is nothing[color=blue]
                      > wrong in using such names, there is no known side effect in any language
                      > or UA. What is true is that it is a Good Thing to choose names with
                      > meaning; for example, the `textarea' element could be named according
                      > to its expected content.[/color]

                      Yes they are different namespaces.
                      [color=blue][color=green]
                      >> This does not deal with getting the text from a text document
                      >> in an iframe which is what I was after.[/color]
                      >
                      > Try referenceToIfra me.document.bod y.firstChild.fi rstChild.nodeVa lue in
                      > Mozilla/5.0.
                      > WFM in Firefox 1.0.7/Linux as an iframe with a plaintext
                      > resource is made available through an embedded HTML document with a
                      > `pre' element containing the resource's content.[/color]

                      referenceToIfra me.document.bod y.firstChild.fi rstChild.nodeVa lue

                      Works in IE too :)

                      Thanks.

                      Aaron


                      Comment

                      • Thomas 'PointedEars' Lahn

                        #12
                        Re: Getting IFRAME text

                        Aaron Gray wrote:

                        Please provide proper attribution, see
                        <http://jibbering.com/faq/faq_notes/pots1.html>
                        vvvvvvvvvvvvvvv vvvvvvvvvvvvvvv vvvvvvvvvvvvvvv vv[color=blue][color=green][color=darkred]
                        >>> This does not deal with getting the text from a text document
                        >>> in an iframe which is what I was after.[/color]
                        >>
                        >> Try referenceToIfra me.document.bod y.firstChild.fi rstChild.nodeVa lue in
                        >> Mozilla/5.0.
                        >> WFM in Firefox 1.0.7/Linux as an iframe with a plaintext
                        >> resource is made available through an embedded HTML document with a
                        >> `pre' element containing the resource's content.[/color]
                        >
                        > referenceToIfra me.document.bod y.firstChild.fi rstChild.nodeVa lue
                        >
                        > Works in IE too :)[/color]

                        Nice :) However it is not supposed to work in IE/Windows < 5.0 and I'm
                        not sure about IE/Mac either. W3C DOM support was introduced in IE pretty
                        late, so you should definitely feature-test it on run time.
                        [color=blue]
                        > Thanks.[/color]

                        You're welcome.


                        PointedEars

                        Comment

                        • Aaron Gray

                          #13
                          Re: Getting IFRAME text

                          > Please provide proper attribution, see[color=blue]
                          > <http://jibbering.com/faq/faq_notes/pots1.html>
                          > vvvvvvvvvvvvvvv vvvvvvvvvvvvvvv vvvvvvvvvvvvvvv vv[/color]



                          !:)

                          Aaron


                          Comment

                          • Thomas 'PointedEars' Lahn

                            #14
                            Re: Getting IFRAME text

                            Aaron Gray wrote:
                            [color=blue][color=green]
                            >> Please provide proper attribution, see
                            >> <http://jibbering.com/faq/faq_notes/pots1.html>
                            >> vvvvvvvvvvvvvvv vvvvvvvvvvvvvvv vvvvvvvvvvvvvvv vv[/color]
                            >
                            > http://jibbering.com/faq/faq_notes/pots1.html#ps1TopPs
                            >
                            > !:)[/color]

                            Why, I did not top-post :)


                            F'up2 PointedEars

                            Comment

                            • Aaron Gray

                              #15
                              Re: Getting IFRAME text

                              > Why, I did not top-post :)

                              Just joking :)

                              I did think when I wrote that post that the context was odd.

                              Aaron


                              Comment

                              Working...