window.addEventListener('load', function() { var imgs = document.getElementsByTagName('img'), objs = document.getElementsByTagName('object'), pre = document.createElement('pre'), scr = document.createElement('script'); for (var i = 0; i < imgs.length; i++) { // add pre tag from object data var m = imgs[i], o = objs[i], p = pre.cloneNode(); m.parentNode.insertBefore(p, m.nextSibling); p.innerHTML = o.contentWindow.document.body.textContent; // set appearnce of pre tag var g = getComputedStyle(m), s = p.style; s.lineHeight = 1.5; s.padding = '1em'; s.height = 'calc(' + g.height + ' - 2em)'; s.width = 'calc(100% - ' + g.width + ' - 2em)'; // add dummy script for Auto Reload var ary = Array(m.src, o.data), b = document.body; for (var j = 0; j < ary.length; j++) { var c = scr.cloneNode(); c.src = ary[j]; b.appendChild(c); } } });