I want to set the iframe height automatically to the content height of the iframe where the max-height 800 px. This means all iframes smaller than 800 px have no scroll bar and all iframes bigger than 800 px are 800 px high with a scroll bar. I already have tried:
- set the iframe height automatically
- Adjust width height of iframe to fit with content in it
- How to change height of iframe based on dynamic conent within the iframe?
- adjust iframe height based on the content
- Automatic Iframe height
I don't know what I'm doing wrong, I guess it is again just one simple litte line, the folders are:
style.css
index.html
Scripts/index.js
Sides/pictures.html
Pics/Picture.png
Pictures, Styles and other functions from the index.js are functional. Here the code:
HTML of index.html:
<div id="pictures">
<iframe src="Sides/pictures.html">
Pictures
</iframe>
</div>
HTML of pictures.html:
<h1><img src="../Pics/Pictures.png" width="32" height="32">Pictures</h1>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
Lorem i
CSS for iframes:
iframe {
width: 65%;
max-height:800px;
margin: auto;
display:block;
border: 1px solid transparent;
border-radius: 10px;
background: rgba(0, 0, 0, 0.9);
padding: 0 0 0 0.5em;
}
index.js
// Auto height for all iframes
$("iframe").load(function() {
// http://www.w3schools.com/jsref/dom_obj_frame.asp
try {
var body = $(this).contents().find('body');
this.height = 1;
this.height = body.attr('scrollHeight');
} catch(e){}
});
So you can see I tried a lot and I know not all of this methods are valid but I wanted them tested. And instead of
$("iframe").load(function()
I also tried
$("iframe").each(function()