jQuery( document ).ready(function( $ ) { url = parent.document.URL; var iframe = document.createElement('iframe'); iframe.setAttribute('id', 'customer-chatbox'); iframe.setAttribute('allow', 'microphone; autoplay; camera;'); iframe.setAttribute("src", "https://activesupport.online/widget_content?url="+url); iframe.style.width = "75px"; iframe.style.height = "75px"; iframe.style.position = 'fixed'; iframe.style.overflow = 'hidden'; iframe.style.zIndex = 999999; iframe.style.left = 0; iframe.style.marginLeft = '5px'; iframe.style.bottom = 0; iframe.border = 0; iframe.marginwidth = 0; iframe.marginWidth = 0; iframe.marginheight = 0; iframe.marginHeight = 0; iframe.frameBorder = 0; document.body.appendChild(iframe); var responsive_width = "768"; var widget_is_open = false; function adjustIframeSize() { var x = document.getElementById("customer-chatbox"); if (!x) return; if (widget_is_open) { if ($(window).width() <= responsive_width) { $(x).css({"width": "100%", "height": "100%", "margin-right": "0px"}); x.contentWindow.postMessage('responsive', '*'); } else { $(x).css({"width": "370px", "height": "500px", "margin-right": "5px"}); x.contentWindow.postMessage('desktop', '*'); } } else { $(x).css({"width": "75px", "height": "75px", "margin-right": "5px"}); } } $(window).on('load resize', adjustIframeSize); window.addEventListener('message', function(e) { if (e.data === 'widget_open') { widget_is_open = true; adjustIframeSize(); } else if (e.data === 'widget_close') { widget_is_open = false; adjustIframeSize(); } }, false); });