I want to display my page inside another page via Iframe.
The problem is that the iframe doesn't resize automatically (height).
How can I resize it automatically? Or maybe there is better way to display one page inside another?
I want to display my page inside another page via Iframe.
The problem is that the iframe doesn't resize automatically (height).
How can I resize it automatically? Or maybe there is better way to display one page inside another?
Here's one way: http://www.mattcutts.com/blog/iframe-height-scrollbar-example/
If the height of the frame may change after it's loded (e.g. expanding/collapsible regions) then you can set up a polling mechanism to periodically resize the frame in case the size has changed. Like this:
<html>
<head> <title>Parent frame</title> </head>
<body onload="window.setTimeout(resizeFrame, 250)" bgcolor="#cccccc">
<script type="text/javascript">
// Firefox worked fine. Internet Explorer shows scrollbar because of frameborder
function resizeFrame() {
var f = document.getElementById('childframe');
if (f.style.height != f.contentWindow.document.body.scrollHeight + "px")
f.style.height = f.contentWindow.document.body.scrollHeight;
window.setTimeout(resizeFrame, 250)
}
</script>
<p>Parent frame.</p>
<p>Parent frame.</p>
<p>Parent frame.</p>
<p>Parent frame.</p>
<p>
<iframe frameborder=0 src="./innerframe.htm" name="childframe" id="childframe">
</iframe>
</p>
</body>
</html>
Note: I'm assuming that you're using frames because you're pulling content from another domain. If you're pulling content from the same domain, you might be able to simply use script to fetch the content using XmlHttpRequest, and then inject the HTML into a DIV on the parent page. You can't do this if the content lives on a different domain, due to browsers' cross-site scripting limitations.
setInterval(function() {
var ifm = document.getElementById("ifrmeID");
var h = ifm.contentWindow.document.body.scrollHeight;
ifm.height = h < 400 ? 400 : h;
}, 800);
400 is the default height if you didnt want iframe too short,800(ms) is frequency,you can adjust these two values. put the js in the end of your page which contained iframe .then it will be ok.