Announcement

Collapse
No announcement yet.

EspoCRM in Iframe - Where/How to add the Javascript code?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • EspoCRM in Iframe - Where/How to add the Javascript code?

    Hi,

    I need to add EspoCRM to an Iframe. I will have to deal with an Iframe Cross-Domain code so that I can read the height in pixels of the EspoCRM generated HTML.

    My requirement is to add a custom Javascript code to all pages of EspoCRM.

    I would like to add this code at the end of the EspoCRM html:

    Code:
        // Cross-domain iframe Height
        function inIframe(){
            if(top != self){
                var contentHeight = $('#no-more-tables').height(); //Just this part I did with jQuery as I was sure that the document uses it
                postSize(contentHeight);
            }
        }
    
        function postSize(height){
             var target = parent.postMessage ? parent : (parent.document.postMessage ? parent.document : undefined);
    
            if(typeof target != "undefined" && document.body.scrollHeight){
                target.postMessage(height, "*");
                }
        }
    
        inIframe();
    How can I do this?

    Best Regards,
    André Lopes.

  • #2
    Hi again,

    After searching a little bit, I've tried to add the JavaScript Code to "public/html/main.html" with this after </body>:

    Code:
    <script>
        $(document).ready(function() {
    
            // Cross-domain iframe Height
            function inIframe(){
                if(top != self){
                    var contentHeight = $('body').height(); //Just this part I did with jQuery as I was sure that the document uses it
                    postSize(contentHeight);
                }
            }
    
            function postSize(height){
                var target = parent.postMessage ? parent : (parent.document.postMessage ? parent.document : undefined);
    
                if(typeof target != "undefined" && document.body.scrollHeight){
                    target.postMessage(height, "*");
                }
            }
    
            inIframe();
    
        });
    </script>
    The code does not work as expected because the "$(document).ready(function()" is executing the code after all HTML is ready, the $('body').height(); always read 96, and this is not the height after the page finish loading.

    My question is, where can I place this code so that is only executed when all HTML is ready(finished loading) ?

    Any clues?

    Best Regards,
    André Lopes.

    Comment

    Working...
    X