function initLegalTour(opt) { var domElement = document.createElement("div"), domStyle = domElement.style, titleBar = $('.TitleBar'); domStyle.position = "absolute"; domStyle.top = (opt.top + titleBar.outerHeight()) + 'px'; domStyle.width = opt.width + 'px'; domStyle.height = opt.height + 'px'; domStyle.left = opt.left + 'px'; domElement.id = "ep-hopscotch-legal-dummy"; document.querySelector('body').appendChild(domElement); }; var iframe = document.querySelector('#' + 'EmbeddedUnityStorefront'), unityHostAndPort = "#Shop.WebUrlUnitySSL".split("?")[0], dataObject = { type: 'GET_LEGAL_TOUR_COORDS', payload: true }, // listener for messages from the "unity iframe" iframeListener = function (e) { var origin = e.origin || e.originalEvent.origin, type = e.data.type; if (origin === unityHostAndPort) { switch(type) { // handle coordinates from "unity iframe" to position the tour dialog case 'LEGAL_TOUR_COORDS': initLegalTour(e.data.payload); guidedTour.start(data); break; } } }; // register listener for communication between iframe and main document $(window).on('message', function (e) { iframeListener(e.originalEvent); }); // wait for iframe iframe.addEventListener('load', function (event) { // send MBO menu via postMessage to iframe iframe.contentWindow.postMessage(dataObject, unityHostAndPort); }, false);