I have a simple HTML code like this:
<!DOCTYPE html>
<html>
</head>
<script>
function func() {
var x = document.getElementById("frm").contentWindow.document;
document.getElementById("val").innerHTML = "scrollHeight is: " + x.documentElement.scrollHeight;
}
</script>
</head>
<body>
<button id="val" onclick="func()">getScrollHeight</button>
<br>
<br>
<iframe id="frm" src="https://www.wikipedia.org/" width="100%"></iframe>
</body>
</html>
I have a problem with above code:
When I clear the "src" attribute of IFrame(src="") and then click on the "getScrollHeight" button, it shows a number(in my browser it shows 150. The value is not important), But when I fill out the "src" attribute with a web address(for example src="https://www.wikipedia.org/") and then click on the button, it shows nothing. Why does this happen? Why can't I get the scroll height when the IFrame has a content?
My browser is chrome (also edge).
Thanks for any suggestion.