User Tools

Site Tools


room_108

(function() { //////////////////////////////////////////// // CONFIGURE THESE TO MATCH YOUR USE CASE // //////////////////////////////////////////// // set this to a selector for the element that contains the entire UI // you want to access via the iframe -- for a Shiny app, it might be // a div with Bootstrap's container-fluid class var containerSelector = "FBB"; // this should be the root URL of the parent frame (DokuWiki) which you want // to allow to send messages to the child var allowedOrigin = "https://agrobacterium.science" /////////////////////// // END CONFIGURATION // /////////////////////// function sendHeightOf(querySelector) { var container = document.querySelector(querySelector); if (container.scrollHeight !== undefined) { var h = container.scrollHeight; parent.postMessage(h, "*"); } else { console.log("No element corresponding to querySelector " + querySelector + " found, or element did not have property scrollHeight."); } } // cross-browser compatible infrastructure var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent"; var eventer = window[eventMethod]; var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message"; // listen for resize message from parent window (see point ② below) eventer(messageEvent, function(e) { if (e.origin == allowedOrigin) { sendHeightOf(containerSelector); } else { console.log("Was expecting a message from " + allowedOrigin + ", got " + e.origin + " instead."); } }); window.onload = function() { // inform parent at least once after load (see point ① below) sendHeightOf(containerSelector); // monitor self-initiated changes in size (see point ③ below) var mo = new MutationObserver(function() { sendHeightOf(containerSelector); }); mo.observe(document, {subtree: true, childList: true, characterData: true}); }; })();

room_108.txt · Last modified: 2019/05/03 00:36 by sxd