iframe autoheight [英] iframe autoheight
问题描述
我到处搜索了包括这里,并且一直没有找到一个好的解决方案。我遇到了这个问题,它可以在除了Firefox和IE之外的任何浏览器上运行:(帮助? b sizeIFrame();
jQuery(#ifrm)。load(sizeIFrame);
});
function sizeIFrame(){
var videoBrowser = jQuery (#ifrm);
var innerDoc = videoBrowser.get(0).contentDocument?
videoBrowser.get(0).contentDocument.documentElement:
videoBrowser.get(0).contentWindow .document.body;
videoBrowser.height(35);
videoBrowser.height(innerDoc.scrollHeight + 35);
}
,它位于同一个域中,这里是我的< iframe>
< iframe id =ifrmsrc =http:// localhost:8080 / linkconsulting / temp.htmlwidth =100%frameborder =0 scrolling =no>< / iframe>
$ c> localhost ,但是它稍后仍然会在同一个域中。
更新:
S o我注意到这不起作用,因为它似乎干扰tiny.scrollbar插件或反之亦然。不知道在这里做什么:($ / b>
我最终采取了不同的方法。并将它们插入div中。以下是代码,以防其他人需要它。谢谢大家的耐心和帮助。
< script>
function getFile(){
var content = jQuery('#servercontent')[0];
var ifrm = jQuery '#ifrm')[0];
content.innerHTML = ifrm.contentDocument.body.innerHTML;
< / script>
< body>
< div id =servercontent>< / div>
< iframe id =ifrmsrc =webinsamedomain.comwidth =100%frameborder =0scrolling =nostyle =display:none;onload =getFile();>< / iframe>
< / body>
I've searched everywhere including here and haven't been able to come up with a good solution. I ran into this and it works in everybrowser except Firefox and IE :( Help?
jQuery(function() {
sizeIFrame();
jQuery("#ifrm").load(sizeIFrame);
});
function sizeIFrame() {
var videoBrowser = jQuery("#ifrm");
var innerDoc = videoBrowser.get(0).contentDocument ?
videoBrowser.get(0).contentDocument.documentElement :
videoBrowser.get(0).contentWindow.document.body;
videoBrowser.height(35);
videoBrowser.height(innerDoc.scrollHeight + 35);
}
and it's on the same domain and here's my <iframe>
<iframe id="ifrm" src="http://localhost:8080/linkconsulting/temp.html" width="100%" frameborder="0" scrolling="no"></iframe>
I'm testing on localhost
right now but it will still be on same domain later.
Update: So I've noticed that this is not working because it seems to be interfering with tiny.scrollbar plugin or viceversa. Not sure what to do here :(
Well I ended up taking a different approach. I got the contents from inside the iframe and inserted them inside a div. Here's the code in case anyone else needs it.. Thank you all for your patience and great help.
<script>
function getFile(){
var content = jQuery('#servercontent')[0];
var ifrm = jQuery('#ifrm')[0];
content.innerHTML = ifrm.contentDocument.body.innerHTML;
}
</script>
<body>
<div id="servercontent"></div>
<iframe id="ifrm" src="webinsamedomain.com" width="100%" frameborder="0" scrolling="no" style="display:none;" onload="getFile();" ></iframe>
</body>
这篇关于iframe autoheight的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!