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>
<?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>
Comment