Web Analytics Made Easy -
StatCounter How to get all data of iframe in a string. - CodingForum

Announcement

Collapse
No announcement yet.

How to get all data of iframe in a string.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get all data of iframe in a string.

    I'm trying to copy information in one iframe to another iframe with javascript. I am using firefox and information from my local domain so there are no security issues. However I'm just not getting it. I'm not sure what the right element name is. Seems like there should be something that gives me all the code in the iframe with a single call stuffed nicely within a string. That's really what I want, all the information in the iframe in one nice big string. But how to get it...

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" >
    <head>
    <title>Test1</title>
    <meta name="revision" content="$Id: $" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <link rel="stylesheet" type="text/css" href="/local-stylesheet.css"/>
    <script>
    function copy_frame(argFrm1, argFrm2) {
    //window.frames["ifrm2"].document.body.innerHTML = "<p>hello</p>"; // works, frame has hello
    //window.document.body.innerHTML = "<p>hello</p>"; // works, replaces document with hello.
    window.document.body = window.frames["ifrm1"].document.body; // this works!
    //window.frames["ifrm2"].document.body = window.frames["ifrm1"].document.body; // This causes both to go blank.
    }
    </script>
    </head>

    <body>
    <div id="insert"></div>

    <div id="div4frm1">
    <iframe name="ifrm1" id="ifrm1" src="http://www.local.com" >
    use firefox
    </iframe>
    </div>

    <div id="div4frm2">
    <iframe name="ifrm2" id="ifrm2" src="" >
    Get firefox
    </iframe>
    </div>

    <div id="move">
    <INPUT TYPE="button" onClick="copy_frame(ifrm1, ifrm1);" value="copy" ID="b">
    </div>
    </body>
    </html>

  • #2
    You try innerHTML?

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

    Comment


    • #3
      Originally posted by A1ien51 View Post
      You try innerHTML?

      Eric
      Yes, I believe I tried that. It is option 1 in the following. I also tried 8 other variations. Nothing has given me what I want:
      Code:
      //window.frames["ifrm2"].document.body.innerHTML = window.frames["ifrm1"].document.body.innerHTML;   // 1)
      //window.frames["ifrm2"].document.body.outerHTML = window.frames["ifrm1"].document.body.outerHTML;   // 2)
      //window.frames["ifrm2"].document.body = window.frames["ifrm1"].document.body;                       // 3)
      //window.frames["ifrm2"].document.innerHTML = window.frames["ifrm1"].document.innerHTML;             // 4)
      //window.frames["ifrm2"].document.outerHTML = window.frames["ifrm1"].document.outerHTML;             // 5)
      //window.frames["ifrm2"].document = window.frames["ifrm1"].document;                                 // 6)
      //window.frames["ifrm2"].innerHTML = window.frames["ifrm1"].innerHTML;                               // 7)
      //window.frames["ifrm2"].outerHTML = window.frames["ifrm1"].outerHTML; // 8)
      //window.frames["ifrm2"] = window.frames["ifrm1"];   // 9)
      Option 1 only pulls out the body, and doesn't work with frames either, but that's beside the point because I want the whole document including header information and such. In one big string...

      Comment


      • #4
        Why don't you use the XMLHttpRequest object? responseText is all you need.

        Eric
        Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

        Comment


        • #5
          Originally posted by A1ien51 View Post
          Why don't you use the XMLHttpRequest object? responseText is all you need.

          Eric
          I was hoping it was simpler. Perhaps just a function call...

          Comment


          • #6
            I think you want to access the documentElement property. Try something like this:
            Code:
            window.frames["ifrm2"].document.documentElement.outerHTML=window.frames["ifrm1"].document.documentElement.outerHTML;

            Comment

            Working...
            X