I am refactoring my personal website, it's a portfolio in which I want to load different pages depending on the project the user wants to see, and I have an issue while loading a subpage in an iframe. I have tested a bunch of different javascripts and css methods to automatically detect the height of the subpage but everything that I am testing either seems not to be able to read the height of the subpage or as the same effect that setting height="100%"
in the iframe, which only fills the parent div instead of extending it.
Here is what I got at the moment:
In the head:
<script>
function resizeIframe(obj) {
obj.style.height = obj.contentWindow.document.documentElement.scrollHeight + 'px';
}
</script>
My iframe:
<iframe sandbox="allow-same-origin allow-scripts" lang="en" src="subpage.html" allowTransparency="true" scrolling="no" frameborder="0" width="100%" onload="resizeIframe(this)"></iframe>
Can someone help me there? Am I missing something?
P.S: I'm self taught in both webdesign and programing so it is possible that my question is stupid or that I am missing something obvious... sorry if that's the case :/
P.S bis: I know the use of iframe is not always the best, but in my case it allows me to integrate and maintain webpages really easily as I only need to export my pages from a Notion I set up with all the content from my website subpages and voila... No need to create all by myself all the subpages of the website and it would be so easy to maintain