var def_width = "100%"; var def_height = "690"; var frame_url = "http://app.glazingvault.com/new/75"; var pathArray = frame_url.split('/'); var protocol = pathArray[0]; var host = pathArray[2]; var url = protocol + '//' + host; var parent = document.getElementById("frameTarget").parentNode; var current_url = window.location.href; var iframe = document.createElement('iframe'); // set the iframe source iframe.src = frame_url; // Inject the iFrame into the DOM iframe.width = def_width; iframe.height = def_height; iframe.scrolling = 'no'; iframe.id ="frame"; iframe.style.border = '1px solid #f3f3f3'; iframe.style.marginTop = '0px'; iframe.style.marginBottom = '0px'; iframe.setAttribute('sandbox', 'allow-same-origin allow-top-navigation allow-scripts allow-popups allow-forms'); var currentScript = document.currentScript || (function () { var scripts = document.getElementsByTagName('script'); return scripts[scripts.length - 1]; })(); currentScript.parentElement.appendChild(iframe); function requestSize() { document.getElementById('frame').contentWindow.postMessage("request_height", url); } setInterval(function() { requestSize() }, 700); document.getElementById('frame').onload = function() { requestSize(); }; function receiveMessage(event) { var data = event.data; if(data.type == "height") { if(data.height >= def_height) iframe.height = parseInt(data.height); } else if(data.type == "reset") { iframe.height = def_height; } } window.addEventListener("message", receiveMessage);