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
    Oct 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question How to get text from an iframe?

    Hello
    I need to get text from an iframe.
    I tried this example (I've found it on this board):

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Example</title>
    <style type="text/css">
    </style>
    <script type="text/javascript">
    // <![CDATA[
    
    window.onload = function()
    	{
    	// treat iframe_window as if it were your iframes window (which it is)
    	var iframe_window = window.frames["my_iframe"];
    	// compare the following line to: window.document.getElementsByTagName("body")[0].innerHTML;
    	var iframe_body_html = iframe_window.document.getElementsByTagName("body")[0].innerHTML;
    	alert(iframe_body_html);
    	}
    
    // ]]>
    </script>
    </head>
    <body>
    
    <iframe name="my_iframe" id="my_iframe" src="example.html"></iframe>
    
    </body>
    </html>
    but it works only with window.onload event.
    I need to get this text dynamically (e.g. on click).

    could you give me some example?

    Regards.

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    966
    Thanks
    19
    Thanked 211 Times in 209 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="generator" content="daveyerwin">
    <title>Example</title>
    <style type="text/css">
    </style>
    <script type="text/javascript">
    // <![CDATA[
    
    function clicked()
    	{
    	// treat iframe_window as if it were your iframes window (which it is)
    	var iframe_window = window.frames["my_iframe"];
    	// compare the following line to: window.document.getElementsByTagName("body")[0].innerHTML;
    	var iframe_body_html = iframe_window.document.getElementsByTagName("body")[0].innerHTML;
    	alert(iframe_body_html);
    	}
    
    // ]]>
    </script>
    </head>
    <body>
    
    <iframe name="my_iframe" id="my_iframe" src="example.html"></iframe>
    <button type="button" onclick="clicked()">
    </body>
    </html>

  • Users who have thanked DaveyErwin for this post:

    222333 (10-16-2011)

  • #3
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up

    works like a charm!

    Thanks a lot

    Regards.


  •  

    Posting Permissions

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