Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macintosh Adding contents of an iframe to a textarea dynamically

    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

  • #2
    Regular Coder
    Join Date
    May 2005
    Location
    Michigan, USA
    Posts
    566
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Note this only works if the file is on your server. It will not work across server.

    Code:
    <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>
    Note: I do not test code. I just write it off the top of my head. There might be bugs in it! But if any thing I gave you the overall theory of what you need to accomplish. Also there are plenty of other ways to accomplish this same thing. I just gave one example of it. Other ways might be faster and more efficient.

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    you may use also:
    obj.contentWindow.document.documentElement.innerHTML
    instead of
    obj.contentWindow.document.getElementsByTagName('html')[0].innerHTML
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •