JSFiddle - React, Tailwind, and code Playground

by rjurd

HTML

<iframe id='rob' src="http://www.smh.com.au" width="100%" height="300">
    <p>Your browser does not support iframes.</p>
</iframe>
<a href="#" onclick="getFrameContents()">Get the content</a>
<div id='output'>2345</div>

JavaScript

function calcHeight(p_id) {
    //find the height of the internal page
    var el = $(p_id).contents();
    $('#output').append('<div>' + '' + '</div>');
    //var the_height = el.contentWindow.document.body.scrollHeight + 20;
    //document.getElementById(p_id).height = the_height;
    //alert(document.getElementById(p_id).contentDocument.body.innerHTML);
}

$(function() {
    $('#rob').load(function() {
        setTimeout("calcHeight('rob')", 500);
    });
});

function getFrameContents() {
    var iFrame = document.getElementById('rob');
    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);
}