1

i have a sample html file.

<html>
    <head>
        <script src="sample1.js"></script>
    </head>
    <body>
        <iframe id="sif" src="if.html"></iframe>
    </body>
</html>

how can add text or elements in the if.html with sample1.js?

  • 1
    http://stackoverflow.com/questions/926916/how-to-get-the-bodys-content-of-an-iframe-in-javascript – damian Aug 07 '14 at 18:15
  • I don't know if this is your real code, but keep in mind if the iframe HTML content is originating from other domain no modification would be possible. – Rolice Aug 07 '14 at 18:20

1 Answers1

1

thanks kingdamian42.
yes its work.

sample1.js

function getFrameContents()
{
    var iFrame =  document.getElementById('sif');
    var iFrameBody;
    if ( iFrame.contentDocument ) 
    { // FF
        iFrameBody = iFrame.contentDocument.getElementsByTagName('body')[0];
    }
    else if ( iFrame.contentWindow ) 
    { // IE
        iFrameBody = iFrame.contentWindow.document.getElementsByTagName('body')[0];
    }
    alert(iFrameBody.innerHTML);
}