Get the height of the iframe content when the domain and protocol match, but the subdomain is not

I am trying to get an iframe ( https://booking.yourdomain.com from https://www.yourdomain.com ) so that I can set its height. So, all the content is visible like this (I accepted the expression from here ):

var booking_iframe = document.querySelector('iframe');

booking_iframe.onload = function() {
    booking_iframe.style.height = booking_iframe.contentWindow.document.body.offsetHeight + 'px';
}

But this causes the following error:

VM389:1 Uncaught DOMException: Blocked a frame with origin "https://www.yourdomain.com" from accessing a cross-origin frame.
    at <anonymous>:1:54

Domains and protocol are the same, but the subdomain isn’t working,

Any suggestion?

(If you want to play with the debugger, I created test.html using only iframes in the production environment)

-Edit -

As a workaround: Any idea how to enable iframe content scrolling? (tried fixed height and overflow, scroll = yes, but will not work)

+4
1

- , .

, JS , iframe, , iframe:

document.domain = "yourdomain.com";

. https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy#Changing_origin.

: iframe , iframe-resizer.

+1

Source: https://habr.com/ru/post/1682769/


All Articles