...

View Full Version : Adding contents of an iframe to a textarea dynamically



COLT CLINT
08-10-2005, 12:17 PM
Hi,

I'm trying to send the contents of an <iframe> to a textarea dynamically -no onclick action -;






<html>
<head>
<title>Untitled</title>
<script>
function o() {
document.getElementById('iframe_1').src = document.getElementById('selectbox_1').value;
}

function test(){
string=window['iframe_1'].document.body.innerHTML
string=string.substring(5,string.length-6)
document.getElementById('textarea_1').value = string
}
</script>



</head>

<body>


<select id="selectbox_1" onChange="o()";>
<option value="page1.txt">page1</option>
<option value="page2.txt">page2</option>
<option value="page3.txt">page3</option>
</select>

<iframe id="iframe_1" name="iframe_1" src="" onload="test()" width=200 height=100></iframe>

<textarea id="textarea_1" value="document.getElementById('iframe_1').value" cols=50 rows=10 ></textarea>



</body>
</html>


Thanks

COLT CLINT

SpirtOfGrandeur
08-10-2005, 12:33 PM
Note this only works if the file is on your server. It will not work across server.


<html>
<head>
<title>Untitled</title>
<script type='text/javascript'>
function test(obj){
document.getElementById('textarea_1').value = obj.contentWindow.document.getElementsByTagName('html')[0].innerHTML;
}
</script>
</head>

<body>
<iframe id="iframe_1" name="iframe_1" src="./LabSchedule.asp" onload="test(this)" width=200 height=100></iframe>

<textarea id="textarea_1" cols=50 rows=10 ></textarea>
</body>
</html>

Kor
08-10-2005, 01:20 PM
you may use also:
obj.contentWindow.document.documentElement.innerHTML
instead of
obj.contentWindow.document.getElementsByTagName('html')[0].innerHTML



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum