How to get the height of the called page in the iframe of HTML and act as the height of this iframe?

content of HTML: < iframe src= "/ 123.htm" name= "my111" id= "my222" onload= "gaodu ()" width= "100%" marginwidth= "10px" frameborder= "0" scrolling= "no" > < / iframe >

how do I get the height of "/ 123.htm" and use this height as the height of the iframe tag in HTML? The pages called by
iframe are different pages of the same site, which is probably what you call "same domain". Please help me not complete the code, use iframe in index.html, call / 123.html, and set the text height of 123.html to the height of iframe in index.html.

get down on your knees and ask the god for an answer. In a hurry.

Apr.07,2022

carry an answer from SO:

$('iframe').load(function() {
    this.style.height =
    this.contentWindow.document.body.offsetHeight + 'px';
});
Don't forget to load jQuery first.

< hr >

https://stackoverflow.com/que...



<script>
        function setIframeHeight(iframe) {
            if(iframe) {
                var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
                if(iframeWin.document.body) {
                    iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
                }
            }
        };

        window.onload = function() {
            setIframeHeight(document.getElementById('external-frame'));
        };
    </script>
    <iframe src="backtop.html" frameborder="0" scrolling="no" id="external-frame" onload="setIframeHeight(this)"></iframe>
Menu