471,076 Members | 1,182 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,076 software developers and data experts.

How do you copy an iframe's content to another iframe?

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. Somebody please give me some help here, perhaps show me the right tag names. I'm tired of trial and error guessing. Are there any good books that deal with firefox, iframes, javascript, and asynchronous AJAX?

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
  3. "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" >
  6.     <head>
  7.       <title>Test1</title>
  8.       <meta name="revision" content="$Id: $" />
  9.       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  10.       <meta name="keywords" content=""/>
  11.       <meta name="description" content=""/>
  12.       <link rel="stylesheet" type="text/css" href="/local-stylesheet.css"/>
  13.         <script>
  14.             function copy_frame(argFrm1, argFrm2) {
  15.                 //window.frames["ifrm2"].document.body.innerHTML = "<p>hello</p>"; // works, frame has hello
  16.                 //window.document.body.innerHTML = "<p>hello</p>"; // works, replaces document with hello.
  17.                 window.document.body = window.frames["ifrm1"].document.body;  // this works!
  18.                 //window.frames["ifrm2"].document.body = window.frames["ifrm1"].document.body;  // This causes both to go blank.
  19.             }
  20.         </script>
  21.     </head>
  22.  
  23.     <body>
  24.         <div id="insert"></div>
  25.  
  26.       <div id="div4frm1">
  27.           <iframe name="ifrm1" id="ifrm1" src="http://www.local.com" >
  28.                 use firefox
  29.             </iframe>
  30.       </div>
  31.  
  32.       <div id="div4frm2">
  33.           <iframe name="ifrm2" id="ifrm2" src="" >
  34.                 Get firefox
  35.             </iframe>
  36.         </div>
  37.  
  38.         <div id="move">
  39.             <INPUT TYPE="button" onClick="copy_frame(ifrm1, ifrm1);" value="copy" ID="b">
  40.         </div>
  41.     </body>
  42. </html>
Sep 28 '06 #1
1 16274
acoder
16,027 Expert Mod 8TB
Replace
Expand|Select|Wrap|Line Numbers
  1. //window.frames["ifrm2"].document.body = window.frames["ifrm1"].document.body;  // This causes both to go blank.
with
Expand|Select|Wrap|Line Numbers
  1. frames["ifrm2"].document.body.innerHTML=
  2. frames["ifrm1"].document.body.innerHTML;
May 17 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by SF RVN | last post: by
1 post views Thread by pb | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.