S
S
Senseich2020-05-02 00:14:33
JavaScript
Senseich, 2020-05-02 00:14:33

How to get the height of a frame loaded from another domain?

Hello! I am loading the Bitrix 24 form by clicking on a button with the class b24-web-form-popup-btn-3 . The frame with the form is loaded. I need to get the height of this iframe#bx_form_iframe_3 frame .

I try to do like this:

$('.b24-web-form-popup-btn-3').on('click', function() {

        $('iframe#bx_form_iframe_3').load(function() {

            eh = $('iframe#bx_form_iframe_3').contents().find('html').height();
            console.log(eh);

        });
    });

But Null is returned .
So far, the only solution I have found is to search for the height of the block in which the frame is wrapped, and then using setTimeout of 1 second, because the frame is not loaded immediately, so the height is not correct without delay.

But it would be desirable without setTimeout, it seems to me this is a "crutch".

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
y0u, 2020-05-02
@Senseich

If you have access to the iframe's code from another domain, then you can use Window.postMessage() to communicate between the iframe and your page.
If there is no access to the code, then adequately - no way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question