Can't figure out why Chrome / Safari can't get ScrollHeight right here

I just asked a question about why certain js code will not work 100% in Chrome and Safari, but after even more troubleshooting, I think I found out that this is the question I should post.

I have a page in which there is a form. The purpose of this form is an iframe on the same page. Iframe is dynamic and php based.

This is the bottom of my iframe php file:

<body onload="parent.resize_iframe(document.body.scrollHeight)">
<?php echo $display_table; ?>

As you can see, I am calling a function to resize the iframe height on the main page (parent page).

This works fine, and it actually changes, but in Chrome and Safari, the size sets the height “higher” than it should be. Therefore, if the height is 500 pixels, then Chrome and Safari set it to about 2000 pixels, which is the maximum height of the iframe document.

Why is this? One thought may be that the body is not fully loaded before scrollHeight is sent to the resize function, maybe?

Is there any way to make it wait until the document is fully loaded?

One thing that bothers me is that when I click the link on the main page and then click back, the page size changes well and is set to 500 pixels, just like in Chrome / Safari. But this is when I hit "back" in the browser.

, , , , .

+2
1

document.body.scrollHeight :

, ,

, , .

, , iframe. iframe , iframe . , iframe ​​ 2000, - 500, 2000.

, - iframe 1px. ( )

( pointy um..points out) , div , . div

:

?

- , . parent.resize_iframe onload, , HTML, JS, CSS . , . -, , onload. -, - window.onload, . , http://www.webreference.com/programming/javascript/onloads/

+1

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


All Articles