Skip to content

Instantly share code, notes, and snippets.

@pingyen

pingyen/jsIframe.html

Last active Aug 29, 2015
Embed
What would you like to do?
Put JS into Iframe
<iframe id="_if1" scrolling="no" style="width : 100%" ></iframe>
<script>
(function() {
var oIf = document.getElementById('_if1'),
win = oIf.contentWindow,
doc = win.document;
doc.write('<html><head></head><body><script src="http://postpet.jp/webmail/blog/clock_v1_moco.js" ></sc' + 'ript><body></html>');
if(doc.all) {
var scArr = doc.getElementsByTagName('script'),
oSc = scArr[scArr.length - 1];
_check();
return;
function _check() {
var rs = oSc.readyState;
if(rs == 'loaded' || rs == 'complete') {
doc.close();
_height();
return;
}
setTimeout(_check, 100);
}
}
win.onload = _height;
doc.write('<script> document.close(); </sc' + 'ript>');
function _height() {
oIf.style.height = doc.body.scrollHeight + 'px';
}
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment